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 -> SELECT @@IDENTITY... is there in Oracle a better way to go?

SELECT @@IDENTITY... is there in Oracle a better way to go?

From: Giovanni Azua <bravegag_at_hotmail.com>
Date: Mon, 6 May 2002 13:19:56 +0300
Message-ID: <ab5p5q$ff8q6$1@ID-114658.news.dfncis.de>


Hi all,

I was trying to simulate the SELECT @@IDENTITY effect of SQL Server in an Oracle Database and I found a way to achieve the same effect by using the combination: SEQUENCE, TRIGGER ON BEFORE INSERT and a Global Package variable which have a different copy/instance for each different connection/session.

Is there another clearer/straighter way to achieve this effect in Oracle9i?

create table CLIENTS (

    IDClient number(9) not null,
    CONSTRAINT IDClient_pk primary key (IDClient) );

create sequence IDClient_seq

    increment by 1 start with 1;

create or replace trigger CLIENTS_BIR

    before insert on CLIENTS for each row begin

    select IDClient_seq.NextVal
    into :new.IDClient
    from DUAL;
    IdentityPkg.LastIdentity := :new.IDClient; end;
/

.

create or replace package IdentityPkg as   LastIdentity number := -1000;
end IdentityPkg;
/

.

create or replace procedure LastIdentity (

    ident out number ) is
begin

    ident := IdentityPkg.LastIdentity;
end;
/

.

Best Regards,
Giovanni Received on Mon May 06 2002 - 05:19:56 CDT

Original text of this message

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