Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle Primary key and Delphi: How to insert the primary key value automatically ?

Re: Oracle Primary key and Delphi: How to insert the primary key value automatically ?

From: Robert Altena <altena_at_gol.com>
Date: 1997/10/03
Message-ID: <612fpf$5nt$1@godzilla.gol.com>#1/1

Gary England wrote in article <342F23BA.1E1E_at_hiwaay.net>...

>Ger Otten wrote:

 ...
>> Insert into orders (orderno, custno)
>> values (order_seq.NEXTVAL, 1032)
>>
>> Questions:
>>
>> 1. Is it possible to use Oracle Database triggers to automatically fill
 in
>> the next sequence number in the primary key field ?
>> If so how can this be achieved ?

Triggers are not the way to do this. A stored procedure (which takes almost all data to be inserted as parameters will do the trick)

>>
>> 2. If this is not possible I would like to know the following : When I
 have
>> a table open in a grid open in Delphi and I am in the edit
>> mode. When I insert a record can I then get the next sequence number from
>> Oracle and fill it myself in the table ? How do I do that.

Just my $0.02: DON'T use the insert/update capabilities of any data-bound control.
Write your own INSERT and UPDATE sql.

>> 3. Maybe both are possible: What do you prefer ?
>>

Use a TQuery component with a " ... values ( seq_PK.Nextval..." clause

>It can be done with a pre-insert trigger for the table, but that would
>not get you the sequence number back into your program.
>
>Either with or without DB.StartTransaction you can get a value from the
>sequence generator by running a query like:
>
>SELECT mysequence.NEXTVAL from DUAL;
>

This will also work, but generates additional network traffic.

Happy coding,

  Robert Altena Received on Fri Oct 03 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US