ORA-06502:PL / SQL:数字或值错误:字符串缓冲区太小 - 将Clob转换为varchar2

时间:2015-07-30 09:59:12

标签: json oracle plsql clob

我尝试使用api将clob转换为varchar2时出现此错误。

我试图检索的'body'字段是clob,但是我想将它转换为varchar2(1000)。

请告知发生此错误的原因:

       MERGE INTO XXX D
                 USING (
                       select  
                              v_ticket_id ticket_id,
                              json_ext.get_number(json(value(S)),'id') comment_id,
                              json_ext.get_number(json(value(S)),'author_id') author_id , 
                              DBMS_LOB.SUBSTR(json_ext.get_string(json(value(S)),'body'),1000,1) body,
                              json_ext.get_string(json(value(S)),'via.channel')channel,
                              case when lower(json(value(S)).get('public').to_char()) = 'true' then 1 else 0 end  is_public,
                              to_date(replace(replace(json_ext.get_string(json(value(S)),'created_at'),'T',' '),'Z',null), 'YYYY-MM-DD HH24:MI:SS') created_at,
                              sysdate
                              FROM table(PKG.sf_retreive_data('RETREIVE').list_data) S) S

                ON (D.ticket_id = S.ticket_id and D.comment_id = S.comment_id)

                WHEN MATCHED THEN          
                      UPDATE SET   author_id = S.author_id,
                                   body = S.body,
                                   channel = S.channel,
                                   is_public = S.is_public,
                                   created_at = S.created_at, 
                                   bi_updated_time = sysdate

                WHEN NOT MATCHED THEN          
                      insert (ticket_id,comment_id,author_id ,body,channel,is_public,created_at,bi_updated_time)
                      values
                             (S.ticket_id,S.comment_id,S.author_id,S.body,S.channel,S.is_public,S.created_at,sysdate);
               commit;  

我收到此错误: 错误:ORA-06502:PL / SQL:数字或值错误:字符串缓冲区太小

1 个答案:

答案 0 :(得分:0)

问题是该行:                               DBMS_LOB.SUBSTR(json_ext.get_string(json(value(S)),'body'),1000,1)body,

应该已插入varchar2(1000)。

函数DBMS_LOB.SUBSTR无法正常运行。 由于特殊的字符集(Json obj),该字符串比CLOB数据类型大。

解决方案: 插入带有clob列的表(GTT),然后替换为varchar2 XXX表。