Oracle LOB字段操作的一点教训

xiaoxiao2026-04-18  3

      今天有个功能需要对CLOB字段进行操作,期间遇到几个问题,老天眷顾,都算是解决了,记一下,免得日后重蹈覆辙。

      错误一:

ORA-22920: 未锁定含有 LOB 值的行

出现这个问题的原因,是由于select出LOB字段时未加 for update,ORACLE官方文档对该错误的说明:

ORA-22920 row containing the LOB value is not locked Cause: The row containing the LOB value must be locked before updating the LOB value. Action: Lock the row containing the LOB value before updating the LOB value.

  于是加上for update再测,发现错误提示变了,变成下面的:

 

 

     错误二:ORA-01002: 读取违反顺序

出现这个问题的原因是Connection 的 autoCommit属性值为true,改成

conn.setAutoCommit(false); ...... LOB操作 ..... conn.commit(); conn.setAutoCommit(true);

 

就可以了。

 

另外,注意第一步的select时,不要select出非LOB的字段,并且,如果一张表有多个LOB字段,操作顺序也最好按照表里的字段顺序来操作,否则也可能出错。

 

转载请注明原文地址: https://www.6miu.com/read-5047580.html

最新回复(0)