加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle插入或修改 报ORA-01704: 文字字符串太长

发布时间:2020-12-12 14:33:38 所属栏目:百科 来源:网络整理
导读:https://segmentfault.com/a/1190000002923350 今天在操作数据库数据的时候,想要插入一条某个字段是一个很长的字符串(比如一篇文章)的数据,例如: insert into article( id ,title, content ) values ( 1 , '标题' ,68)">'长字符串' ); 或 update articl

https://segmentfault.com/a/1190000002923350

今天在操作数据库数据的时候,想要插入一条某个字段是一个很长的字符串(比如一篇文章)的数据,例如:

insert into article(id,title,content) values(1,'标题',68)">'长字符串');

update article set content = '长字符串' where id = 1;

在使用PL/SQL执行的时候,报ORA-01704: 文字字符串太长错误。

解决方案:

使用存储过程操作数据,如下:

declare
    content clob;
begin
  content := '长字符串';
  insert into article(id,content );
  update article set content = content  where id = 1;
end;

原因分析:sql在执行之前会把所有字符类型的数据转换成VARCHAR2类型,而VARCHAR2类型的最大长度为4000,所以当字符串超过这个长度就会转换失败。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读