Getting Value from the Variable's Value

In this forum you can share stuff related to Oracle 11g, 10g, 9i.
Post Reply
usmaniub
Posts: 1
Joined: Wed Nov 29, 2006 1:43 am
Location: Pakistan

Getting Value from the Variable's Value

Post by usmaniub »

Dear all

I am trying to write a generalize trigger to log the statements executed on the table say table "A" with fields "id number(3), name varchar2(50)". and a log table say
"LOG_A" with field "statement_exe varchar2(1000)"

when i insert the record in the "A" table then insert statment like
"insert into a(id,name) values(1,'asdf');"
must be inserted in the LOG_A table
or
when i delet the record from the "A" table then delete statemend like
"delete from A where id=1 and name='asdf';" must be inserted in the LOG_A table
same for update statement
The trigger is as follow


CREATE OR REPLACE TRIGGER A_INSERT BEFORE INSERT ON A FOR EACH ROW
DECLARE
CURSOR S IS SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME='A';
COLUMN_LIST VARCHAR2(1000) := NULL;
INSERT_COLUMN VARCHAR2(1000) := NULL;
dummy varchar2(100):= null;
dum varchar2(1000) := null;
ab number(10) := 0;
INSERT_STRING AA.A%TYPE;
BEGIN
FOR I IN S LOOP
IF COLUMN_LIST IS NULL THEN
COLUMN_LIST := I.COLUMN_NAME;
INSERT_COLUMN := ':NEW.'||I.COLUMN_NAME;
ELSE
COLUMN_LIST :=COLUMN_LIST ||','||I.COLUMN_NAME;
INSERT_COLUMN := INSERT_COLUMN||','||':NEW.'||I.COLUMN_NAME;
END IF;
END LOOP;
IF INSERTING THEN
INSERT INTO AA(A) VALUES(INSERT_STRING);
INSERT INTO LOG_A(A) VALUES('INSERT INTO A('||COLUMN_LIST||') VALUES('||INSERT_COLUMN||');');
END IF;
END;
/

But the problem is that it inserts the statement in the LOG_A table like
"insert into a(id,name) values (:new.id,:new.name);"
But i require
"insert into a(id,name) values (1,'asdf');"


How can i get the value from variable :new.id that is store as a string in the variable INSERT_COLUMN


I also use EXECUATE IMMEDIATE STATEMENT but the result is same.

Regards for all
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest