Creating sequence in oracle is a very easy task.
Sequences help more at instants like generating new id for a record that has been inserted into oracle table through triggers.
Syntax:-
create sequence [sequence_name] start with [sequence start from] increment by [increment by] [caching]
Nocache clause is used while creating sequence to generate sequences in an order
Example :-
create sequence seq_test start with 1 increment by 1 nocache
Once sequence is created , value can be retrieved using sequence name as
syntax :- select [sequence name].nextval from dual
Example :- select seq_test.nextval from dual.
next_val increments the current value of the sequence and returns the updated value.
Simmillalry to get current value of the sequence we should use currval.
Example :-
select seq_test.currval from dual
No comments:
Post a Comment