Generating sequential values
Generating sequential values is a common database application development problem. The best solution to that problem is to use sequences and sequence expressions in SQL. Each sequence is a uniquely named database object that can be accessed only by sequence expressions.
There are two sequence expressions: the PREVIOUS VALUE expression and the NEXT VALUE expression. The PREVIOUS VALUE expression returns the value most recently generated in the application process for the specified sequence. Any NEXT VALUE expressions occurring in the same statement as the PREVIOUS VALUE expression have no effect on the value generated by the PREVIOUS VALUE expression in that statement. The NEXT VALUE sequence expression increments the value of the sequence and returns the new value of the sequence.
id_values
using
the default attributes, issue the following statement: CREATE SEQUENCE id_values
VALUES NEXT VALUE FOR id_values
1
-----------
1
1 record(s) selected.
UPDATE staff
SET id = NEXT VALUE FOR id_values
WHERE id = 350
INSERT INTO staff (id, name, dept, job)
VALUES (NEXT VALUE FOR id_values, 'Kandil', 51, 'Mgr')