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字段,操作顺序也最好按照表里的字段顺序来操作,否则也可能出错。
相关文档:
步骤:
1.首先,你要有一张表!
CREATE TABLE example(
ID Number(4) NOT NULL PRIMARY KEY,
NAME VARCHA ......
当你在数据库中创建数据表的时候,你需要定义表中所有字段的类型。ORACLE有许多种数据类型以满足你的需要。数据类型大约分为:character, number, date, LOB, 和RAW等类型。虽然ORACLE8i也允许你自定义数据类型,但是它们是最基本的数据类型。
在下面的文章中你将了解到他们在oracle 中的用法、限制以及允许值。
......
CREATE TABLE T_BI_CurrentAccountDetailed
(
OrderDate DATE,
BranchFlag varchar2(3),
SortId varchar2(11),
OrderNo&n ......
SQL
insert into table_name(colum1,colum2)
select colum1,colum2
from opendatasource('sqloledb','data source=服务器名;user id=用户名 ;password=密码 ').database_name.dbo.table_name
如执行出现以下错误”sql server 阻止了对组件 \'ad hoc distributed queries\' 的访问&l ......