User Tools

Site Tools


oracle_accelerator_generating_unique_key_values.htm
Navigation:  SQL Drivers > Oracle >====== Oracle Accelerator Generating Unique Key Values ====== Previous pageReturn to chapter overviewNext page

For many database applications, you will want to automatically generate unique key values for your database records. An Oracle Sequence is simply a sequence number generator. You can select the next number from the Sequence whenever you add a new record.

Generally, we recommend using Oracle Sequences whenever possible to generate your unique key values. Sequences are more efficient because you never get a clash, and you need only two (2) database calls to add your new record.

Oracle Sequences:

To use Oracle Sequences:

1.Define an Oracle Sequence for the auto incremented key.

See your Oracle documentation:

CREATE SEQUENCE GlobalSequence

 INCREMENT BY 1

 START WITH 1

 NOMAXVALUE

 MINVALUE 1

 NOCYCLE

 CACHE 30;

2.Declare a Clarion file to receive the sequence number from the Oracle Sequence like this:

CustomerSequence FILE,DRIVER('ORACLE'),PRE(CUST),CREATE,THREAD

Record            RECORD,PRE()

SequenceNo         LONG

                 END

                END

3.Assign the incremented sequence number to your key field by embedding the following in the WindowManager Method Executable Code Section - PrimeFields embed point:

Access:CustomerSequence.Open

CustomerSequence{Prop:SQL}='Select GlobalSequence.Nextval from dual'

IF ~Access:CustomerSequence.Next()

 Cust:CustNo=SequenceNo

END

where Cust:CustNo is the label of your auto-incremented key field in your Oracle data file.

4.Set the embedded code priority to 7500.

oracle_accelerator_generating_unique_key_values.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1