我有一个查询
String sqlQuery = 'update t1 set col1 = ? where colId = ?';
表格结构:
t1 table
--------------
colId |col1
--------|------
Integer |Clob
-------------
col1 - 值可以超过4000个字符。 因此,当我执行查询时,我收到以下错误:
SQL错误:ORA-01704:字符串文字太长 01704. 00000 - “字符串字面太长”
如何编写sql更新查询。我不想要存储过程?任何人都可以帮助我。
答案 0 :(得分:2)
Clob
字符最长可达2,147,483,647
个字符,因此在您的情况下应该足够了,以防止此问题,而不是将值作为String
字面值提供,仅限于4,000
个字符,只要您已经注意到,请将其作为nAscii流或Clob
提供,分别归功于其中一种方法setAsciiStream
或感谢方法setClob(int parameterIndex, Reader reader)
班级PreparedStatement
。
这是一个具体的例子:
PreparedStatement ps = ...
// - set the value of the input parameter to the input Reader
ps.setClob(1, new StringReader(myStringContent));
// Or setAsciiStream(1, fis);
ps.setInt(2, id);
ps.execute();