how to create a sequence in sql oracle

Veröffentlicht am: 14 Dezember 2022
auf dem Kanal: Oracle Training-Free Oracle Tutorials
12
1

how to create a sequence in sql oracle?

let us first understand what is sequence.

-it is a user created database object that can be shared by multiple users to generate integers.
-it is used for generating unique numbers automatically.
-used to create primary key values.

SYNTAX:

CREATE SEQUENCE sequence_name
START WITH initial_value
INCREMENTED BY increment_value
MINVALUE minimun value
MAXVALUE maximum value
CYCLE|NOCYCLE


STEP 1--------------------------------------------

now before creating a sequence lets create a table first...

create table managers(
col1 number(5)primary key,
col2 varchar2(20));

Name Null Type
---- -------- ------------
COL1 NOT NULL NUMBER(5)
COL2 VARCHAR2(20)


table created.

STEP 2--------------------------------------------

now lets move on to make a sequence using the above syntax..

create sequence manager_a
start with 10
increment by 10
maxvalue 100
minvalue 1
nocycle;

this sequence is with nocycle....lets create one more sequence with cycle...

create sequence manager_b
start with 100
increment by -2
maxvalue 100
minvalue 2
cycle;

now we have created 2 sequences....lets insert it.

STEP 3---------------------------------------------

insert into managers values(manager_a.nextval,manager_b.nextval);

by using this string we have inserted 5 values..

STEP 4-------------------------------------------

lets check it in the table.

so here we have successfully created 2 sequences one with minus incremented value and other with add values.


thanks for watching.

do like share and subscribe.


Auf dieser Seite können Sie das Online-Video how to create a sequence in sql oracle mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Oracle Training-Free Oracle Tutorials 14 Dezember 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 12 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!