oracle ORA-01704: string literal too long问题分析
今天使用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;
这都可以解决问题。