oracle merge into函数中插入clob字段

当使用Merge into 函数向ORACLE数据库中插入或更新数据时,报错“ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值”,使用如下方法可以把String转换为clob。

需要引入 JDBC drivers (ojdbc14.jar or ojdbc5.jar)

CLOB tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);//Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();// Write the data into the temporary CLOB
tempClobWriter.write(stringData);// Flush andclose the stream
tempClobWriter.flush();
tempClobWriter.close();//Close the temporary CLOB
tempClob.close();

myStatement.setCLOB(column.order, tempClob);

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。