oracle ORA-01704: string literal too long


導出數據時,在SQL拼接處,提示 oracle ORA-01704: string literal too long

 sql:

 WITH already_in AS
 (SELECT distinct REGEXP_SUBSTR('-999,CX201702210003,CX201702270003,……,CX201702270004', '[^,]+', 1, level) col   from dual
  connect by level <= length(regexp_replace(''-999,CX201702210003,CX201702270003,……,CX201702270004',  '[^,]*')) + 1)
select pro.*, u.user_name PROJECT_MANAGER_NAME
  from cp_p pro  left join cdc_u u    on u.user_id = pro.PROJECT_MANAGER
 where 1 = 1   and exists (select * from already_in al where al.col = pro.project_code)
   AND pro.project_manager not in (select info.user_id  from cdc_user_info info  where info.user_name in ('fff'))
 
拼接的字符串超長導致“string” 拋異常。減少了拼接字符后,順利執行。
注意:在拼接sql時,用於某類型字段的拼接,需要注意其長度。事先預測一下需要拼接的字符最長會達到多少,超長的話可以使用clob類型字段。
盡量避免拼接超長字符用在sql中,如必須,可以聲明一個事務變量,或者分頁處理(或分段連接處理)。
 
網上有相關處理方式,引用一下:

有兩種方法可以解決:

1.使用存儲過程,把超長文本保存在一個變量中,然后再insert update

declare
v_clob clob :='一個長文本';
begin
  insert into table values(a,3,:clob);
 end;

2.字符串拼接,update使用字符串拼接

 update mall_config set category_info='安全防護:3003,' where id=1;

update mall_config set category_info=category_info||'|標准件:1040140,1035382,' where id=1;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM