If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Triggers, procedures and inserting into a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-13-02, 16:13
MGZ MGZ is offline
Registered User
 
Join Date: Apr 2002
Location: Calgary, Canada
Posts: 30
Triggers, procedures and inserting into a table

hello

I have a table that currently has a trigger on it.

Code:
CREATE trigger update_host
    BEFORE UPDATE ON host FOR EACH row
		EXECUTE PROCEDURE host_hist_ins;
What I want to happen is this:

When the trigger goes off, it takes the current record that is being updated from the host table, and insert it into the host_hist table.

The problem I am having is how do I write it so it is parsing the value of the ID (Primary key) into the code ?

Code:
...
DECLARE
  cursor a_cur IS SELECT host_id FROM host where id = [this is the variable I want from the update]   
BEGIN
...

Hopefully that makes sense

thanks
Reply With Quote
  #2 (permalink)  
Old 11-13-02, 16:41
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
In the trigger, you will have to pass the ID to the procedure. The ID will be :NEW.ID

CREATE trigger update_host
BEFORE UPDATE ON host FOR EACH row
BEGIN
host_hist_ins( :NEW.ID );
END;

The procedure requires a parameter to receive the value:

PROCEDURE host_hist_ins ( p_id IN host.id%TYPE ) IS
BEGIN
...
END;
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 11-13-02, 17:03
MGZ MGZ is offline
Registered User
 
Join Date: Apr 2002
Location: Calgary, Canada
Posts: 30
heh after some reading I found the :new and ld :-) I have to get my mind out of parsing variables to web pages.

thanks for the help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On