Question on update CLOB column when the column value is null
posted 11 years ago
I have a Oracle database table column that is a CLOB column. I have a program that updates individual records of this table. For the CLOB column, I use the following steps to update the column value: 1. Use "Select...for update" statement to select the row. 2. Use getClob() method on the ResultSet to get the locator and cast the Clob locator to oracle.sql.Clob. 3. Get the outputstream of this Clob locator and write the data.
The problem is that getClob() returns null when the column is null. Of all the examples I've seen so far, the CLOB clumn either contains value or is already initialized to empty_clob. One way I can think of to work around the problem is that if getClob() returns null, I use an update statement to set the CLOB field to empty_clob and then repeat the steps I listed above. But it's kind of clumsy. I would very much appreciate some inputs on a better approach.