今天使用sql在oracle直接insert update一個表時,出現ORA-01704: string literal too long的錯誤,我們的sql是
update mall_config a set a.category_info='|標准件:1040140,1035382,1036586,1035383,1032451,1032469,141903,1036587,1044047,1035380,1035385,1455,1035379,1035376,1035464,141906,1046869,1035386,141909,1035377,141901,1046875,1042427,1032449,1035338,1035468,1046879,1035343,10353,1035466,1036788,1035467,1046874,1035446,1035341,1035449,1032470,1035339,1035342,1046868,1040201,1046870,1035447,1042428,1035463,1035340,1035450,1035445,1035444,1040197,1035381,1035629,1046877,141904,1035448,1035458,1035465,1040211,1035387,1035337,1035443,1035378,1042787,141902,1035388,141908,1046878,1042627,1032401,1046871,1035384,1036588,1035459......';
其中category_info字段是clob類型,而后面字符串內容很長,雖然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;
這都可以解決問題。