Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with trigger

Status
Not open for further replies.

Bronte1226

Technical User
Oct 18, 2002
123
US
I am trying to create a trigger involving 2 tables.
If a record is updated or inserted, after the insert I need to update a field in another table. For example if in the first table there is an inserted row then i need the field in the other table to be updated to a particular text string where the id fields that reference each other are equal (for each row) if the field is updated then i need to change the field in the other table to a different string (where the id's are equal again) I have something like this but it isn't working. I think that i am using the if then else statement incorrectly.

CREATE OR REPLACE TRIGGER BOOKS_TRG AFTER INSERT OR
UPDATE OF LEVEL ON BOOKS FOR EACH ROW BEGIN
UPDATE CLIENT
IF CLIENT_BOOK = 'L'
THEN SET CLIENT_BOOK = 'U'
ELSE SET CLIENT_BOOK = 'U'
WHERE CLIENT.CLIENT_ID = BOOKS.CLIENT_ID
END IF;
END;
/

I am new to triggers so I feel lost. Help!
 

In triggers you must refer to a column like:
:new.<column_name>
or:
:eek:ld.<column_name>

And you can use 'if inserting' and 'if updating'.

So you can construct something like:

begin

if inserting then

if :new.client_book = 'L'
then
update client
set book = ...
where client_id = :new.client_id;
else
update client
set book = ...
where client_id = :new.client_id;
end if;

elsif updating then

...
...
...

end if;

end;
/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top