Maurice Perry
Maurice Perry

Reputation: 32831

How to append text to an oracle clob

Is it possible to append text to an oracle 9i clob without rereading and rewriting the whole content?

I have tried this:

PreparedStatement stmt = cnt.prepareStatement(
        "select OUT from QRTZ_JOBEXEC where EXEC_ID=? "
            + "for update",
        ResultSet.TYPE_FORWARD_ONLY,
        ResultSet.CONCUR_UPDATABLE);
try {
    stmt.setLong(1, id);
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) {
        Clob clob = rs.getClob(1);
        long len = clob.length();
        Writer writer = clob.setCharacterStream(len+1);
        try {
            PrintWriter out = new PrintWriter(writer);
            out.println(line);
            out.close();
        } finally {
            writer.close();
        }
        rs.updateClob(1, clob);
        rs.updateRow();
    }
    rs.close();
} finally {
    stmt.close();
}

But I'm getting an "Unsupported feature" exception on the call to setCharacterStream.

Upvotes: 3

Views: 6237

Answers (2)

Gary Myers
Gary Myers

Reputation: 35401

DBMS_LOB.APPEND is the key.

Upvotes: 6

Kevin Burton
Kevin Burton

Reputation: 11936

if you are just adding text then you could try a simple

UPDATE qrtz_jobexec SET out = out || ? WHERE exex_id=?

Upvotes: 1

Related Questions