Use SERIAL

Description

You can access and update a serial by serial name and a reserved word pair.

Syntax

serial_identifier.CURRENT_VALUE

serial_identifier.NEXT_VALUE

Example

The following example shows how to create a table athlete_idx where athlete numbers and names are stored and how to create the instances by using a serial order_no.

CREATE TABLE athlete_idx( code INT, name VARCHAR(40) );

INSERT INTO athlete_idx VALUES (order_no.NEXT_VALUE, 'Park');

INSERT INTO athlete_idx VALUES (order_no.NEXT_VALUE, 'Kim');

INSERT INTO athlete_idx VALUES (order_no.NEXT_VALUE, 'Choo');

INSERT INTO athlete_idx VALUES (order_no.NEXT_VALUE, 'Lee');SELECT * FROM athlete_idx;

 

         code  name

===================================

        10000  'Park'

        10002  'Kim'

        10004  'Choo'

        10006  'Lee'

Caution

When you use a serial for the first time after creating it, NEXT_VALUE returns the initial value. Subsequently, the sum of the current value and the increment are returned.