ORA-22992删除远程表问题中对LOB的引用

时间:2015-02-04 10:03:18

标签: oracle casting subquery sql-insert lob

我正在尝试使用多个select语句插入表CAPTURED_DATA_01。我能够插入值EVENT_ID,ENV_ID,BRAND_ID,BP_ID但是现在我还要插入SUBSCRIPTION_ID值即将来自使用select远程表中的语句。我已经测试过的查询并且运行正常以获取SUBSCRIPTION_ID。但是当我尝试使用这个select语句以便将SUBSCRIPTION_ID的值插入到我的插入查询中时,我得到的错误是我在子查询中使用了cast函数作为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)

1 个答案:

答案 0 :(得分: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;
/

Read more关于批量收集和forall进行批量查询/插入。

如果您有可用于merge子句的内容,您也可以按照建议使用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);

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