Skip to Main Content
  • Questions
  • Equivalent of identity column (sql server 7.0) In oracle !

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, OP.

Asked: October 19, 2000 - 1:53 pm UTC

Last updated: December 03, 2002 - 9:14 pm UTC

Version: 8.1.5

Viewed 1000+ times

You Asked

Dear Tom,
Hi !

How are you doing ?

My question is :- I am developing an Application in Oracle

There is a need to generate Unique value for ecode in EMP
table.According to the SPECIFICATION I cannot make use of
SEQUENCE.When I write Trigger to insert Unique value for
ecode it gives "mutating table problem".

Is SQL Server we have something known as "IDENTITY Column"
Is there anything euivalent to that in ORACLE8i.

Thanks & Regards
OP

and Tom said...

Why cannot you use a SEQUENCE if the SEQUENCE is totally hidden from the application.

the only way to do this in Oracle is:

create sequence emp_seq;
create trigger emp_trigger
before insert on emp for each row
begin
select emp_seq.nextval into :new.empno from dual;
end;
/


The CLIENT will never see or access the sequence. If you are not allowed to use sequences for "portability", then you cannot use identities in SQLServer. In order to implement the SQLServer identity type in Oracle -- the required code is above. Since the client never sees the sequence, never touches it, is not aware of it -- you should (have to) make an exception in this case.

This is as portable as using the proprietary identity type from SQLServer.

If there is some logical reason you cannot use a sequence, submit another question with the reasoning.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Finally, the answer first...

Dave Bender, December 03, 2002 - 9:14 pm UTC

I'm new to Oracle, too, and I've been hunting all over for the answer to the same question -- how to create an identity field(Sybase/SQL Server), or a SERIAL data type (Postgres), or an AutoNumber (MS Access).

In my web wanderings, it seems that is a bit of a religious issue in this world that's new to me. The question was asked many times in different forums and was answered with a fair amount of venom about what a bad idea it is.

I appreciate that you provided the answer right off the bat in an example that worked the first time. Now I can go read up on why this is such a bad idea....



finally we got it in Oracle 12c

biju george, November 22, 2013 - 12:49 pm UTC

IDENTITY column is introduced in Oracle 12c :-)

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library