Search code examples
oracle-databaseclobsql-merge

Using Oracle CLOB value inside MERGE


I tried to copy values between tables with this query:

MERGE INTO workflow W
   USING ( 
       SELECT distinct pr.workflow_id, pr.name, pr.description FROM workflow_revision pr, workflow pw WHERE pw.id = pr.workflow_id 
   )WR
   ON ( W.id = WR.workflow_id )
   WHEN MATCHED THEN
   UPDATE SET W.name = WR.name, W.description = WR.description

But it gives, the following error: ORA-00932: inconsistent datatypes: expected - got CLOB

When remove that description column from the query then it works fine. It's a longtext.

I just don't know how to fix this. Can you help me?


As @eaolson requested the layout of the tables, I give the original screenshot: enter image description here


After @Lukasz Szozda 's commit I took this as answer:

MERGE INTO workflow W
USING (
   SELECT workflow_id, name, (CAST (description AS VARCHAR2(4000))) AS description FROM workflow_revision
)WR
ON (W.id = WR.workflow_id)
WHEN MATCHED THEN
UPDATE SET W.name = WR.name, W.description = WR.description;

But as he also warned; this is a accaptable answer as long as the description column length max 4000(or the value you give in there) is.


Solution

  • There is no need for JOIN:

    MERGE INTO workflow W
    USING (SELECT workflow_id, name, description FROM workflow_revision)WR
       ON (W.id = WR.workflow_id)
    WHEN MATCHED THEN
    UPDATE SET W.name = WR.name, W.description = TO_LOB(WR.description);