Empty clob not getting set to NULL

183
May 24, 2019, at 4:10 PM

I'm merging a clob into my oracle database using Groovy. Everything is working fine, except when there is an empty Clob. Instead of making my table column NULL, it's setting it to an empty string.

Clob myClob = CLOB.createTemporary(sql.getConnection(), false, CLOB.DURATION_SESSION);        
while ((row = reader.readNext()) != null) {
    myClob.truncate(0)
    myClob.setString(1,row[17])
        def stmt = /
                    MERGE INTO my_table a
                    USING (
                      SELECT    ${row[0]} id,
                                ${myClob} clob_column
                      FROM dual) e
                    ON (a.id = e.id)
                    WHEN MATCHED THEN
                      UPDATE SET 
                            a.clob_column = e.clob_column
                      /
   def runsql = sql.execute(stmt)

}

I've tried passing "NULL" instead of my Clob value and it works, but I can't seem to figure out how to conditionally pass it to my merge statement when the clob is empty. I can't just set "myClob" to null, because then it fails when it loops and tries to truncate it. I was hoping I could do something like an elvis operator in the closure:

${myClob ?: null} 

or

${if(myClob.length() > 0) then myClob else null}

but neither seem to work.

Rent Charter Buses Company
READ ALSO
Adding a Text editor using netbeans platform

Adding a Text editor using netbeans platform

Im developing a Netbeans platform application and Im trying to reuse editor componentI know how to use the Diff component but not the simple editor

146
Verify Amazon price in asc order-Java Selenium

Verify Amazon price in asc order-Java Selenium

Scenario: Search a product in Amazon and then sort by price low to highThe logic that I thought of is- A) go through each page using while page count

155
Java: synchronization does not block if it changes

Java: synchronization does not block if it changes

Related Java will synchronized block if changed?

178
Unit test throws exception

Unit test throws exception

I am trying to unit test method that is responsible for returning the number of fat of given product

208