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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Autoincrement functionality

Re: Autoincrement functionality

From: Rajagopal Venkataramany <rajagopalvr_at_excite.com>
Date: Tue, 1 Aug 2000 19:49:52 -0700 (PDT)
Message-Id: <10576.113546@fatcity.com>


Hi,

  If you use a stored procedure interface to populate the table,   then the stored procedure can be used to get the next value from   the sequence and set the key field accordingly, before insert can   take place. This would be an ideal and recommended way of doing it   and possibly avoid creating the trigger if the trigger is created   just for assigning key values.

  If you have a environment, where inserts to the table may happen   viz sqlplus or sqlloader or by other similar means where the   insert to the table cannot be interfaced via the stored procedure,   then for such cases, triggers make sense.

Regards
Rajagopal Venkataramany

On Tue, 01 Aug 2000 10:56:14 -0800, ORACLE-L_at_fatcity.com wrote:

> Hi All,
> I am porting a schema to Oracle from mysql that uses
> AUTOINCREMENT to produce the primary key.
>
> In order to keep the application code the same I have
> to get a number from a sequence and insert into the primary key
> column at the database level.
>
> The only way I have figured out is to use a before insert trigger
> something like:
>
> WARNING: THIS IS UNTESTED PSUEDO CODE
>
> CREATE TRIGGER AUTOINCREMENT
> BEFORE INSERT ON TABLE TEST
> FOR EACH ROW
> BEGIN
> :new.PRIMARY_KEY_ROW = TEST_NUM.nextval;
> END;
>
> Has anyone done this?
> Any other ideas?
>
> I am in digest mode so I will not respond until tomorrow.
>
> TIA
> Dave
>
> --
> Dave Morgan
> Senior Database Administrator
> Internet Barter Inc.
> www.bartertrust.com
> 408-982-8774
> --
> Author: Dave Morgan
> INET: dmorgan_at_bartertrust.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).

Regards
Rajagopal Venkataramany


Received on Tue Aug 01 2000 - 21:49:52 CDT

Original text of this message

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