Oracle ORA-01704: string literal too long問題分析

來源:互聯網
上載者:User

今天使用sql在Oracle直接insert update一個表時,出現ORA-01704: string literal too long的錯誤,我們的sql是

update mall_config  a set a.category_info='|標準

其中category_info欄位是clob類型,而後面字串內容很長,雖然clob可以足夠可以儲存這麼長的字串,但是sql語句的文法解析對欄位卻有長度限制,文字字串過長!

有兩種方法可以解決:

1.使用預存程序,把超長文本儲存在一個變數中,然後再insert update

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

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

  1. update mall_config set category_info='安全防護:3003,' where id=1;  
  2. update mall_config set category_info=category_info||'|標準件:1040140,1035382,' where id=1;  

這都可以解決問題。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.