通过带有 CLOB 绑定的 JDBC 执行 sql 语句
我有以下查询(列日志的类型为 CLOB):
UPDATE table SET log=? where id=?
当使用 setAsciiStream 方法将长度超过 4000 个字符的值放入日志列时,上面的查询工作正常。
但我不想替换该值,而是想附加它,因此我的查询如下所示:
UPDATE table SET log=log||?||chr(10) where id=?
上面的查询不再起作用,我收到以下错误:
java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
I have the following query (column log is of type CLOB):
UPDATE table SET log=? where id=?
The query above works fine when using the setAsciiStream method to put a value longer than 4000 characters into the log column.
But instead of replacing the value, I want to append it, hence my query looks like this:
UPDATE table SET log=log||?||chr(10) where id=?
The above query DOES NOT work any more and I get the following error:
java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,您必须使用 PL/SQL 块来完成您想要的操作。 假设有一个
id
1 的条目,以下内容对我有用:It looks to me like you have to use a PL/SQL block to do what you want. The following works for me, assuming there's an entry with
id
1:BLOB 在 SQL 中是不可变的(当然,除了将它们设置为 NULL 之外),因此要追加,您必须先下载 Blob,在本地连接,然后再次上传结果。
通常的解决方案是使用公共键和告诉数据库如何对行进行排序的序列将多条记录写入数据库。
BLOBs are not mutable from SQL (well, besides setting them to NULL), so to append, you would have to download the blob first, concatenate locally, and upload the result again.
The usual solution is to write several records to the database with a common key and a sequence which tells the DB how to order the rows.