Oracle 使用 JDBC 将单表常量与 CLOB 合并
作为这个问题的后续,我需要以下场景的帮助:
在Oracle中,给定一个简单的数据表:
create table data (
id VARCHAR2(255),
key VARCHAR2(255),
value CLOB);
我正在使用以下合并命令:
merge into data
using (
select
? id,
? key,
? value
from
dual
) val on (
data.id=val.id
and data.key=val.key
)
when matched then
update set data.value = val.value
when not matched then
insert (id, key, value) values (val.id, val.key, val.value);
我正在通过 JDBC 从 Java 应用程序调用查询。
当“value”字符串很大时,上述查询会导致以下 Oracle 错误:
ORA-01461: cannot bind a LONG value for insert into a long column
我什至按照文档设置了“SetBigStringTryClob”属性 此处 具有相同的结果。
鉴于“值”是 CLOB,是否可以实现我想要的行为?
编辑:客户端环境是Java
As a follow-up to this question, I need help with the following scenario:
In Oracle, given a simple data table:
create table data (
id VARCHAR2(255),
key VARCHAR2(255),
value CLOB);
I am using the following merge command:
merge into data
using (
select
? id,
? key,
? value
from
dual
) val on (
data.id=val.id
and data.key=val.key
)
when matched then
update set data.value = val.value
when not matched then
insert (id, key, value) values (val.id, val.key, val.value);
I am invoking the query via JDBC from a Java application.
When the "value" string is large, the above query results in the following Oracle error:
ORA-01461: cannot bind a LONG value for insert into a long column
I even set the "SetBigStringTryClob" property as documented here with the same result.
Is it possible to achieve the behavior I want given that "value" is a CLOB?
EDIT: Client environment is Java
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有在帖子中具体提到,但从问题的标签来看,我假设您是通过 Java 执行此操作的。
我在刚刚完成的项目中使用这样的代码取得了成功。 此应用程序使用 Unicode,因此如果您的问题域仅限于标准 ASCII 字符集,可能会有更简单的解决方案。
您当前是否在使用 OracleStatement.setCLOB() 方法? 这是一件非常尴尬的事情,但我们无法以其他方式解决它。 您必须实际创建一个临时 CLOB,然后在 setCLOB() 方法调用中使用该临时 CLOB。
现在,我已经将其从工作系统中删除,并且必须进行一些临时调整,因此,如果这在您的情况下似乎不起作用,请告诉我,我会回去看看是否可以得到一个更小的工作示例。
当然,这假设您使用的是 Oracle Corp. JDBC 驱动程序(ojdbc14.jar 或 ojdbc5.jar),这些驱动程序可在 $ORACLE_HOME/jdbc/lib 中找到
。
德维恩·金
You haven't mentioned specifically in your post, but judging by the tags for the question, I'm assuming you're doing this from Java.
I've had success with code like this in a project I just finished. This application used Unicode, so there may be simpler solutions if your problem domain is limited to a standard ASCII character set.
Are you currently using the OracleStatement.setCLOB() method? It's a terribly awkward thing to have to do, but we couldn't get around it any other way. You have to actually create a temporary CLOB, and then use that temporary CLOB in the setCLOB() method call.
Now, I've ripped this from a working system, and had to make a few ad-hoc adjustments, so if this doesn't appear to work in your situation, let me know and I'll go back to see if I can get a smaller working example.
This of course assumes you're using the Oracle Corp. JDBC drivers (ojdbc14.jar or ojdbc5.jar) which are found in $ORACLE_HOME/jdbc/lib
Regards,
Dwayne King