How to Generate Serial Number in Oracle Forms?

Here I am giving two examples to generate the serial number in Oracle Forms using System.Cursor_Record system variable and using Sequence database object.

Generate Serial Number Using System.Cursor_Record in Oracle Forms

In Oracle Forms, you have a tabular database block, and for each set of records, you want to generate a serial number starting from 1 when a new record is getting created. Then you can use the simple below code on any button click event, for example, Add New Record button or WHEN-CREATE-RECORD trigger at the data block level to generate the serial number using System.Cursor_Record. Below is the example:

        /* srlno is a column in the emp data block */
	:emp.srlno := :system.cursor_record;

Adding serial number column in Oracle Forms.

But what if you want to generate the continuation of serial number whenever a set of records are getting created in that block? Then use the Sequence database object to perform this task. Below is the example:

Generate Serial Number Using Sequence Object in Oracle Forms

	l_seq number;
	Select emp_seq.nextval into l_seq from dual;
	:emp.srlno := l_seq;

See also:

Leave a Comment