how to create a sequence in sql oracle

Pubblicato il: 14 dicembre 2022
sul canale di: 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.


In questa pagina del sito puoi guardare il video online how to create a sequence in sql oracle della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Oracle Training-Free Oracle Tutorials 14 dicembre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 12 volte e gli è piaciuto 1 spettatori. Buona visione!