PLSQL归档LONG数据类型,错误:

时间:2013-11-21 14:49:42

标签: sql plsql insert oracle11g archive

我正在使用Oracle 11g,尝试使用PL / SQL将历史超过90天的任何内容移动到历史记录表中。但我有一个使用LONG数据类型的列。所以我找到了我认为应该有效的SQL,但它会出错:

    BEGIN
FOR ROW IN
       (SELECT  MESSSAGE_KEY,
          DISTRIBUTION_ID,
          MESSAGE,
          SYSTEM_NAME,
          MESSAGE_TYPE,
          MESSAGE_NAME,
          MESSAGE_STATUS,
          LATEST_INBOUND,
          CREATETS,
          MODIFYTS,
          CREATEUSERID,
          MODIFYUSERID,
          CREATEPROGID,
          MODIFYPROGID,
          LOCKID,
          ENTITY_KEY,
          ENTITY_NAME,
          ENTITY_VALUE
        FROM    NWCG_INBOUND_MESSAGE
        WHERE   TO_CHAR (createts, 'YYYYMMDD') >= TO_CHAR ((sysdate-90), 'YYYYMMDD')
    )
    LOOP
    INSERT INTO NWCG_INBOUND_MESSAGE_H
    VALUES (    
                ROW.MESSSAGE_KEY,
          ROW.DISTRIBUTION_ID,
          ROW.MESSAGE,
          ROW.SYSTEM_NAME,
          ROW.MESSAGE_TYPE,
          ROW.MESSAGE_NAME,
          ROW.MESSAGE_STATUS,
          ROW.LATEST_INBOUND,
          ROW.CREATETS,
          ROW.MODIFYTS,
          ROW.CREATEUSERID,
          ROW.MODIFYUSERID,
          ROW.CREATEPROGID,
          ROW.MODIFYPROGID,
          ROW.LOCKID,
          ROW.ENTITY_KEY,
          ROW.ENTITY_NAME,
          ROW.ENTITY_VALUE
           );
END LOOP;
END;

这是我得到的错误:

Error report:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 2
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    
*Action:

从我的研究看起来这个错误看起来很多,但我找不到任何人的解决方案......任何想法?

1 个答案:

答案 0 :(得分:1)

long数据类型是我一直建议不要在Oracle数据库中存储文件或长字符串的原因之一。如果没有恢复到C和OCI,就很难使用。

现在我们有了clob和blob,它们在PL / SQL和SQL中是合理可用的。但是在Oracle数据字典中仍然会发现很多LONG数据类型。特别是在XXX_VIEWS(user_views,all_views,dba_views)中,这是一个真正的问题。也许原始开发人员应该将其命名为UNUSABLE: - )。

当LONG内容小于32 KB时,有一种解决方法;为了完整的功能,我建议迁移到CLOB或使用C.祝你好运!

--
-- This sample code works when the long is smaller than 32 KB.
-- It is known to work on 9i, 10g, 11g r1, 11g r2, but it assumes
-- that a LONG smaller than 32 KB can be put in a PL/SQL variable.
-- And then cast.
--
-- You might want to add an exception handler to handle exceptions
-- when the size is larger than 32 KB. In this sample, this situation
-- can not occur; the where clause with text_length ensures that.
--
declare
  l_text_as_long  long;
  l_text_as_clob  clob;
  l_text_length   user_views.text_length%type;
begin
  select viw.text
  ,      viw.text_length
  into   l_text_as_long
  ,      l_text_length
  from   user_views viw
  where  viw.view_name = upper(l_object_name)
  and    viw.text_length <= 32767 /* To fix a problem when accessing a view that is larger than 32K, we have this condition. */
  ;
  l_text_as_clob := cast(l_text_as_long as clob);
  ... do something interesting ...
end;