Oracle LOB欄位操作的一點教訓

來源:互聯網
上載者:User

今天有個功能需要對CLOB欄位進行操作,期間遇到幾個問題,老天眷顧,都算是解決了,記一下,免得日後重蹈覆轍。

      錯誤一:

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

出現這個問題的原因,是由於select出LOB欄位時未加 for update,ORACLE官方文檔對該錯誤的說明:

引用文字代碼
1.ORA-22920 row containing the LOB value is not locked   
2. 
3.Cause: The row containing the LOB value must be locked before updating the LOB value.   

4. 
5.Action: Lock the row containing the LOB value before updating the LOB value.  
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,改成

Sql代碼
1.conn.setAutoCommit(false);  
2. 
3.......  
4. 
5.LOB操作  
6. 
7......  
8. 
9.conn.commit();  
10. 
11.conn.setAutoCommit(true); 
conn.setAutoCommit(false);

......

LOB操作

.....

conn.commit();

conn.setAutoCommit(true);
 

就可以了。

 

另外,注意第一步的select時,不要select出非LOB的欄位,並且,如果一張表有多個LOB欄位,操作順序也最好按照表裡的欄位順序來操作,否則也可能出錯。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.