Create sequence with SQL in OpenEdge

Create sequence with SQL in OpenEdge

Sequences provides a bucket from which incremental numbers can be pulled. It is easy to create sequence in OpenEdge with both ABL and SQL. Documentation of sequence is covered quite well on https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dmsrf/create-sequence.html.

The easiest way to create a sequence is like so:

create sequence pub.seq_customer_id
start with 0,
increment by 1,
nocycle;

This will create a sequence with an initial value of 0. When we ask for next value from this sequence, we will receive 1. If called again, we will receive 2, and so on.

Retrieve the next number from this sequence, use nextval

select seq_customer_id.nextval from department fetch first 1 rows only;

Retrieve the current value of the sequence using currval. Note the 2 rs in currval.

select seq_customer_id.nextval from department fetch first 1 rows only;

Get information about the sequence from sysprogress like so:

select * from sysprogress.syssequences;

Be sure to see other topics listed on Modern web applications and API with OpenEdge, SQL, ODBC and PHP.