Kohan95
Kohan95

Reputation: 10359

auto_increment with varchar in oracle

i have this table

CREATE TABLE WishList(
    idWishList VARCHAR2(40 BYTE) ,
    WishListName  VARCHAR2(40 CHAR) NOT  NULL,
    id_User  VARCHAR2(40 BYTE) NOT  NULL
)

now how can i use auto_increment with varchar in oracle ??

Upvotes: 0

Views: 1723

Answers (2)

Adelf
Adelf

Reputation: 706

As I remember, Oracle doesn't have an auto_increment functionality. It has sequences and developers should add special function like getNextId() and use it in insert statements like

insert into table (id,...) values(getNextId() ,..)

So, you can implement you own function which returns new id for your field with your own algorithm.

Upvotes: 1

A.B.Cade
A.B.Cade

Reputation: 16905

You can add a trigger:

create or replace trigger some_trig_name
before insert on WishList
for each row
begin
:new.idWishList := to_char(your_sequence.nextval);
end some_trig_name;

In the example I used a seq but you can put whatever you want

Upvotes: 2

Related Questions