Home » RDBMS Server » Server Administration » Please give me a hand.
Please give me a hand. [message #372882] Thu, 15 March 2001 10:06 Go to next message
pinG
Messages: 1
Registered: March 2001
Location: MUMBAI
Junior Member
Hi,
Could you help me with the problem below?
There is a table with a trigger which produces a sequence no for each record before inserted. What I want to do is to get the sequence no when I insert a new record. How could I do this?
Re: Please give me a hand. [message #372885 is a reply to message #372882] Thu, 15 March 2001 11:17 Go to previous messageGo to next message
Balamurugan.R
Messages: 91
Registered: March 2001
Member
Hi,

First of all i couldn't understand your problem fully. Upto my mind, If you already
created the sequence then you can easily insert
to the field with seqname.nextval directly or
u can insert through the before insert trigger for
that table. If this is not the soloution please
let me know your problem clearly.

With Regards,
Balu
Re: Please give me a hand. [message #372888 is a reply to message #372882] Thu, 15 March 2001 12:09 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
By definition, the sequence number is only known once the record is inserted, and as the trigger doesn't return anything to you, you need to read the value from the table you just inserted into. e.g. select max(pk_col) from tab1
where col1 = 'My 1st field inserted'
and col2 = 'My 2nd field inserted' etc.

You would need the max() because the rest of the rec doesn't garantee uniqueness.

Maybe an easier way to work the problem is to remove the trigger, let your application retrieve the sequence "select my_seq.nextval from dual;" before you insert the record. I'm thinking here of something like an and order entry screen. Remember that any failed inserts will cause you to loose that seq number which you may not want...
Re: Please give me a hand. [message #372901 is a reply to message #372882] Fri, 16 March 2001 07:23 Go to previous message
me
Messages: 66
Registered: August 2000
Member
in version 8.0 and up you can use the Returning clause
Previous Topic: Decode help
Next Topic: Re: Query response time
Goto Forum:
  


Current Time: Mon Jun 03 02:38:14 CDT 2024