Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

Serial Function

Description

The Serial function consists of the SERIAL_CURRENT_VALUE and SERIAL_NEXT_VALUE functions.

The SERIAL_CURRENT_VALUE function returns the current serial value, which is the same value as serial_name.current_value.

This function returns as much added value as interval specified. The serial interval is determined by the value of a CREATE SERIAL ... INCREMENT BY statement. SERIAL_NEXT_VALUE(serial_name, 1) returns the same value as serial_name.next_value.

To get a large amount of serials at once, specify the desired number as an argument to call the SERIAL_NEXT_VALUE function only once; which has an advantage over calling repeatedly serial_name.next_value in terms of performance.

Assume that an application process is trying to get the number of n serials at once. To perform it, call SERIAL_NEXT_VALUE(serial_name, N) one time to store a return value and calculate a serial value between (a serial start value) and (the return value). (Serial value at the point of function call) is equal to the value of (return value) - (desired number of serials) * (serial interval).

For example, if you create a serial starting 101 and increasing by 1 and call SERIAL_NEXT_VALUE(serial_name, 10), it returns 110. The start value at the point is 110-(10-1)*1 = 101. Therefore, 10 serial values such as 101, 102, 103, ... 110 can be used by an application process. If SERIAL_NEXT_VALUE(serial_name, 10) is called in succession, 120 is returned; the start value at this point is 120-(10-1)*1 = 111.

Syntax

SERIAL_CURRENT_VALUE(serial_name)

SERIAL_NEXT_VALUE(serial_name, number)

  • serial_name: Serial name
  • number: The number of serials to be obtained
Example

CREATE SERIAL order_no START WITH 10000 INCREMENT BY 2 MAXVALUE 20000;

SELECT SERIAL_CURRENT_VALUE(order_no);

10000

 

-- At first, the first serial value starts with the initial serial value, 10000. So the l0'th serial value will be 10009.

SELECT SERIAL_NEXT_VALUE(order_no, 10);

10009

 

SELECT SERIAL_NEXT_VALUE(order_no, 10);

10019

Remark

If you create a serial and calls the SERIAL_NEXT_VALUE function for the first time, a value of (serial interval) * (desired number of serials - 1) added to the current value is returned. If you call the SERIAL_NEXT_VALUE function in succession, a value of (serial interval) * (desired number of serials) added to the current is returned (see the example above).