You want to capture update dates, with trigger on a view to refresh quickly materialized. But trigger on MV consider inserting and updates are inserts only.

Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

PL/SQL Release 11.2.0.4.0 - Production

CORE Production 11.2.0.4.0

AMT for Linux: Version 11.2.0.4.0 - Production

NLSRTL Version 11.2.0.4.0 - Production

I create the structure of the table like that.

create table test1 (a primary key, b (2) char number, date c, d varchar2 (10), date of e);

create table test2 (number of ab, cd (2) tank, date of the ef, gh varchar2 (10), date of the ij, kl varchar2 (100));

Create materialized view log on test1;

create materialized view fast refresh test1_v on commit in select * from test1;

I have create a trigger of the sample

CREATE OR REPLACE TRIGGER test1_trig

AFTER INSERT OR UPDATE OR DELETE

ON test1_v

FOR EACH LINE

DECLARE

lr_test2 test2% ROWTYPE;

lv_error VARCHAR2 (4000);

BEGIN

lr_test2. AB: =: NEW.a;

lr_test2. CD: =: NEW.b;

lr_test2. GH: =: NEW.d;

IF THE INSERTION

THEN

lr_test2. EF: = SYSDATE;

lr_test2.IJ: = SYSDATE;

lr_test2.KL: = 'INSERT ';

INSERT INTO test2

VALUES lr_test2;

ELSIF UPDATE

THEN

lr_test2.IJ: = SYSDATE;

lr_test2.KL: = 'UPDATE ';

UPDATE test2 = lr_test2 ab WHERE = LINE: OLD.a;

ELSIF REMOVAL

THEN

DELETE FROM test2

AB = WHERE: old.a;

END IF;

EXCEPTION

WHILE OTHERS

THEN

lv_error: = SQLERRM;

INSERT INTO XXDOMINO_FG_DATA_LOAD_ERROR

VALUES ('test1_trig',

: OLD.a,.

"test1_trig,"

LV_ERROR,

SYSDATE);

COMMIT;

END test1_trig;

/

So, if check you my code,.

When I insert EF = SYSDATE, IJ = SYSDATE.

Update EF is not changed, IJ = SYSDATE.

So I like to capture their insertion and update dates.

But if updates or insert arrives on the materialized table. The trigger themselves as an INSERT only.

So how do you capture the updates?

I use the statemnet with out merger with performance and also able to capture the update dates.

CREATE OR REPLACE TRIGGER test1_trig_merge

AFTER INSERT OR UPDATE OR DELETE

ON test1_v

FOR EACH LINE

DECLARE

lr_test2 test2% ROWTYPE;

lv_error VARCHAR2 (4000);

BEGIN

IF THE REMOVAL

THEN

DELETE FROM test2

    AB = WHERE: old.a;

ELSIF INSERTION

THEN

MERGE INTO test2 one

B using (SELECT 1 FROM DUAL)

WE (ab =: new.a)

WHEN MATCHED

THEN

UPDATE the VALUE ab =: NEW.a.

CD =: NEW.b,

GH =: NEW.c

IJ = SYSDATE,

KL = "Update"

AB WHERE =: old.a

WHEN NOT MATCHED

THEN

INSERTING VALUES (: NEW.a,)

: NEW.b,.

: NEW.c.

: NEW.d,.

: NEW.e,.

"INSERT");

END IF;

EXCEPTION

WHILE OTHERS

THEN

lv_error: = SQLERRM;

INSERT INTO XXDOMINO_FG_DATA_LOAD_ERROR

VALUES ('test1_trig',

: OLD.a,.

"test1_trig,"

LV_ERROR,

SYSDATE);

END test1_trig_merge;

/

DISPLAY ERRORS;

Tags: Database

Similar Questions

Maybe you are looking for

  • Set a value in each separate digital output in qnx

    Hello, I have two examples of the Eseries for outputs digital and they seem to work but when I change the value I want to put in the output of dig 1 it does not change. More accurately, I changed the digex1 of the example in this way: Write 0x00 to 0

  • Current problems with windows xp and Internet Explorer e-mail. You want advice

    Problem started when in Internet explorer, I could not send emails. Program would close downm advised by the technical support of Microsoft Windows than windows xp or explore 8 had bad files and needed to do a clean install. Cannot locate the disc fo

  • ontouchstart, ontouchmove, ontouchend in Simulator

    Hi all I'm trying to capture touch events correctly in the Simulator and horribly lacking at home. Consider this test code: testdiv = document.getElementById('mydiv'); testdiv.ontouchstart = function(e) { document.getElementById('mydiv').innerHTML =

  • the use of sqlite

    Hi, I have an application with some pages. I add the code to create the tables in one of the pages and I do all the "CREATE TABLE...". "but when I change to another page, I think I lost all data, isn't? How can I save and load the database I created

  • Photoshop does not open jpeg files

    I'm working on a Mac OS 10.8.5 and run Photoshop CC 2104. For these days so I'm opening a JPEG in photoshop, that it continues to throw up "could not complete your request because the file was not found." No matter where I try to open the file from o