-1

我正在尝试使用多个选择语句插入表 CAPTURED_DATA_01。我能够插入值 EVENT_ID、ENV_ID、BRAND_ID、BP_ID 但现在我还想插入即将到来的 SUBSCRIPTION_ID 值,我将通过在远程中使用 select 语句获得桌子。我已经测试并运行良好的查询以获取 SUBSCRIPTION_ID。但是,当我尝试使用此 select 语句将 SUBSCRIPTION_ID 的值插入到我的插入查询中时,我收到错误,我在子查询中对 SUBSCRIPTION_ID 使用强制转换函数为

SQL Error: ORA-22992: cannot use LOB locators selected from remote tables
22992. 00000 -  "cannot use LOB locators selected from remote tables"
*Cause:    A remote LOB column cannot be referenced.
*Action:   Remove references to LOBs in remote tables

这是我的查询:

Insert into CAPTURED_DATA_01(SUBSCRIPTION_ID) 
select WF.SUBSCRIPTION_ID 
   from 
   (select WF.SUBSCRIPTION_ID from WF_WORKFLOW@FONIC_RETAIL WF,CAPTURED_DATA_01 CP
where WF.SUBSCRIPTION_ID > CP.SUBSCRIPTION_ID and 
WF.SUBSCRIPTION_ID IN
( 
select iw.SUBSCRIPTION_ID
from (
   SELECT TO_NUMBER(REPLACE(REPLACE(REGEXP_SUBSTR(RESPONSE_XML, '<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>\d+</ax2130:id>'), 
   '<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>', ''), '</ax2130:id>', '')) 
   AS SUBSCRIPTION_ID , 
   CAST(REPLACE(REPLACE(
  REGEXP_SUBSTR(REQUEST_XML, '<ns7:orderType>.+</ns7:orderType>'),
    '<ns7:orderType>', ''), '</ns7:orderType>', '')
  AS VARCHAR(100)) AS order_type,
  TO_NUMBER(REPLACE(REPLACE(REGEXP_SUBSTR(RESPONSE_XML, '<ax2147:orderNumber>\d+</ax2147:orderNumber> '), 
   '<ax2147:orderNumber>', ''), '</ax2147:orderNumber> ', '')) 
   AS ORDER_NUMBER,
   CREATE_DATE
   FROM
   SOAP_MONITORING@FONIC_RETAIL 
   where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder' 
) iw
where iw.order_type='SELF_REGISTRATION'
)and WF.NAME='INITIATE_MANDATE' 
and WF.STATUS_ID=0)
4

1 回答 1

1

据我了解,问题是insert总是在本地数据库上运行。

当你只是select在自己的数据库上运行时,Oracle 可以决定(或被提示)在远程数据库上做一些工作;在这种情况下,它将 CLOB 值转换为 number 和 varchar2 类型,并且只有那些非 LOB 值必须通过网络传输到本地数据库以进行进一步处理。

对于插入,它将尝试检索整个 LOB 以在本地对其进行转换,并且它会阻止这种情况的发生 - 大概是由于涉及的潜在数据量。插入的driving_site提示会被忽略,因此您无法像选择时那样调整该行为。

要解决这个问题,您可以通过 PL/SQL 块中的游标将选择和插入分两个步骤进行。一般模式是:

declare
  type cp_tab_type is table of CAPTURED_DATA_01%ROWTYPE;
  cp_tab cp_tab_type;
  cur sys_refcursor;
begin
  open cur for
    select ... -- some value for every column in the table you're inserting
               -- into, in the same order they appear in the DDL
  loop
    fetch cur bulk collect into cp_tab;
    exit when cp_tab.count = 0;
    forall i in 1..cp_tab.count
      insert into CAPTURED_DATA_01 values cp_tab(i);
  end loop;
end;
/

阅读有关批量收集和 forall 以执行批量查询/插入的更多信息。

您也可以按照您的建议使用 amerge如果您有可以用于该on子句的内容;例如,如果event-id根本不存在:

merge into CAPTURED_DATA_01 cp
using (
    select ..
) data
on (cp.event_id = data.event_id)
when not matched then
insert (EVENT_ID,SUBSCRIPTION_ID,EVENT_TIMESTAMP,ENV_ID,BRAND_ID,BP_ID)
values (data.event_id, data.subscription_id, data.start_date,
  data.env_id, data.brand_id, data.bp_id);

您发布的每个问题都会使您的查询变得更加复杂,并且可能会简化很多。

于 2015-02-04T13:05:08.933 回答