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

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

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

数据库

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

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

解决方案:字符串

使用存储过程操做数据,以下:it

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

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

相关文章
相关标签/搜索