How to use CLOB in a trigger

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ths
Posts: 53
Joined: Thu 29 Dec 2011 16:18

How to use CLOB in a trigger

Post by ths » Thu 05 Nov 2015 15:17

Hello,
i have the following problem that may be relevant or not relevant on this forum.
Suppose we have a table with two CLOB columns and a trigger like:

create table clobtable (id number, clob1 clob, clob2 clob);
CREATE OR REPLACE TRIGGER B_IN_UP_CLOBTABLE
BEFORE UPDATE OR INSERT ON CLOBTABLE FOR EACH ROW
BEGIN
:NEW.CLOB2 := :NEW.CLOB1;
END;

If you run Insert and/or Update statements on this table using some tool (Toad):

INSERT INTO CLOBTABLE (id, clob1, clob2) values (1, 'aaaa','bbbb');
update clobtable set clob1 = 'cccc' where id = 1;

you will obtain expected result - both CLOB fields will contain 'aaaa' after Insert and also both fields will be 'cccc' after Update.
However, using ODAC Query Component i get a problem. Automatically generated by the Component Update statement is
UPDATE CLOBTABLE
SET
CLOB1=EMPTY_CLOB()
WHERE
ID = :Old_ID
RETURNING
CLOB1
INTO
:CLOB1
and it works fine for itself. The problem is that the trigger does not work now - the field CLOB2 is empty after this update.
How should i change the code of the trigger to obtain correct result working with a client application that uses DevArt Query Component?

Thanks,
Vladimir

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to use CLOB in a trigger

Post by AlexP » Thu 05 Nov 2015 15:59

Hello,

In order for your trigger to handle when working in OraQuery, you should set the OraQuery.Options.TemporaryLobUpdate property to True.

ths
Posts: 53
Joined: Thu 29 Dec 2011 16:18

Re: How to use CLOB in a trigger

Post by ths » Thu 05 Nov 2015 16:58

Hello Alex,
thank you very much. The test client works now. Could you explain please what are the advantages and disadvantages of setting this property to TRUE or FALSE? In dbMonitor i see that the Update Statement sent to the server is now (TemporaryLobUpdate=TRUE) "a standard" SQL:
UPDATE CLOBTABLE
SET
CLOB1 = :CLOB1
WHERE
ID = :Old_ID

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to use CLOB in a trigger

Post by AlexP » Mon 09 Nov 2015 10:00

Yes, when using this option, DDL is changed, and we ourselves perform all the operations with LOB locators.

Post Reply