Home » SQL & PL/SQL » SQL & PL/SQL » Trigger Creation Help
Trigger Creation Help [message #22655] Mon, 21 October 2002 11:25 Go to next message
Michele
Messages: 77
Registered: December 2000
Member
Hello everyone,
I have little experience when writing trigger bodies, so I need your help. I posted this up on the newbies site as well.
I have a table called Change_Data that stores the table name and column name of tables that were updated. Ex:
Pers_id Tab_name Col_name
1 Cntrctr rep_status
1 Cntrctr gender

What I need to do is set up a trigger(see below) that inserts values into a Temp_table. Since the col_name value is dynamic(as well as datatype of the column),I am running into a problem with writing a valid statement. I put question marks where I am unsure. Basically, the col_name tells me what column changed on the Cntrctr table. I then need to take that value and use it to search against the Cntrctr to get the true value. Ex of Cntrctr:

Pers_id first_name last_name gender rep_status
1 Donald Duck Male Rookie

Here is my trigger so far, you can ignore the first if statement since I am not having a trouble with it.

CREATE OR REPLACE TRIGGER CRYSTAL_TEMP_INS AFTER INSERT ON CHANGE_DATA FOR EACH ROW
Declare
pk number(8);
ADDRESS_REC WRK.ADDRESS%ROWTYPE;
CNTRCTR_REC WRK.CNTRCTR%ROWTYPE;??????

BEGIN
select CRYSTAL_TEMP_SEQ.nextval into pk from dual;
IF :new.tab_name = 'ADDRESS' THEN
select * into ADDRESS_REC from WRK.ADDRESS A where A.pers_id = :new.pers_id;
insert into WRK.CRYSTAL_TEMP (temp_id,pers_id,data_values)
values(pk,:new.pers_id,ADDRESS_REC.street1||ADDRESS_REC.street2 and so on.....);
END IF;

IF :new.tab_name = 'CNTRCTR' THEN
select ? into CNTRCTR_REC from WRK.CNTRCTR C where C.pers_id=:new.pers_id;
insert into WRK.CRYSTAL_TEMP(temp_id,pers_id,data_values)
values(pk,:new.pers_id,?);
END IF;
END;
Re: Trigger Creation Help [message #22657 is a reply to message #22655] Mon, 21 October 2002 11:57 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
http://www.orafaq.net/msgboard/newbies/messages/5118.htm
How could I create table in another user in the same database [message #23703 is a reply to message #22655] Sun, 29 December 2002 08:01 Go to previous message
M. Khaled
Messages: 67
Registered: April 2002
Member
Please help me to create triggering table in another user in the same database i.e while the triggering event is fired it will be stored in a table which is in another user(not remote).
Previous Topic: Specifying custom order for ORDER BY clause
Next Topic: Exiting a sqlplus batch session
Goto Forum:
  


Current Time: Tue May 21 02:18:39 CDT 2024