易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle LOB字段操作的一点教训

今天有个功能需要对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.
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代码 conn.setAutoCommit(false);

......

LOB操作

.....

conn.commit();

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

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


相关文档:

oracle的RBO/CBO优化器

原文地址:http://tech.it168.com/db/o/2006-08-09/200608091935599.shtml        
                              & ......

SQL Server里建ORACLE链接服务器的图解

 首先计算机上必须安装oracle,并配置好服务名
  安装oracle的过程中一般会要求建立一个数据库,也可以之后再创建
这个后面有一个 数据库配置助理 (创建修改数据库的,一般密码创建要求字母开头,大于7位啥的)和一个net配置助理(添加或者修改一个数据库服务名),一般用plsql developer远程操作oracle数据库 ......

oracle 数据类型


当你在数据库中创建数据表的时候,你需要定义表中所有字段的类型。ORACLE有许多种数据类型以满足你的需要。数据类型大约分为:character, number, date, LOB, 和RAW等类型。虽然ORACLE8i也允许你自定义数据类型,但是它们是最基本的数据类型。
在下面的文章中你将了解到他们在oracle 中的用法、限制以及允许值。
  
......

oracle 修改字段类型的方法(转)

因为业务需要,修要修改某个字段数据类型有number(5),变为number(5,2)型
要是没有数据的话直接用以下语句即可
alter   table tb_test modify permile number(5,2);
但是有数据的话 就不能用上面方法了,
alter table tb_test add permile_temp number(5,2)
update tb_test set permile_temp=permile;
alter t ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号