Home » SQL & PL/SQL » SQL & PL/SQL » Need help on how to deal with sequence number
Need help on how to deal with sequence number [message #38349] Fri, 12 April 2002 14:01 Go to next message
Susan
Messages: 102
Registered: October 2001
Senior Member
Hello everyone,
I need insert data through the web. I have two tables (surgery, test). What I need to do is to have the user input data into the surgery table then the test table. In surgery table I have a primary key column (surgeryid), which is a sequence number. After the user input data into the first table, he need input data into the test table, in the test table, there is a foreign key column which reference to the surgeryid column in the surgery table. My question is how can I get surgeryid from the first table and insert it into the second table. In my insert statement to the test table, I tried to use suid.currval but I got an error message that told me the suid.curr had not been defined in the current session. Do somebody have an answer? Thanks in advance.
Re: Need help on how to deal with sequence number [message #38350 is a reply to message #38349] Fri, 12 April 2002 14:31 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
One option would be to use the RETURNING clause on your surgery insert to return the value generated by the sequence. You can hold this value in a variable and then use it for your test insert.

insert into surgery (surgeryid, ...)
 values (suid.nextval, ...)  -- or maybe the sequence is handled by a trigger
 returning surgeryid into v_surgeryid;


As far as using suid.currval, you can reference it in the test insert as long as that insert occurs in the same session (i.e., the session is persistant across the surgery and test inserts).
Re: Need help on how to deal with sequence number [message #38360 is a reply to message #38349] Mon, 15 April 2002 09:58 Go to previous message
Gopal
Messages: 23
Registered: June 1999
Junior Member
declare
temp number(20);
begin
select the_sequence.nextval into temp from dual;
insert into surgery values (temp, ...............);
insert into test values (....,temp, ..........);
end;
Previous Topic: 113 background processes when commit happens
Next Topic: Re: who's logged on????????
Goto Forum:
  


Current Time: Thu Apr 25 16:09:21 CDT 2024