Generate Next ID in a Oracle Table
This example shows how to get next ID from a Oracle table number column.
While you are doing DataBase quering normally you need to have a Primary key
for the table. Then it should be unique. Therefore show how to get first ID for
empty table and next ID for not empty tables in Oracle.
SELECT decode( MAX(cast(ID as integer)),null,0,MAX(cast(ID as integer))) INTO next_id FROM TABLE;
next_id := next_id+1;
-- here ID means Primary key number colum
-- table means your table
If you got some thing from this please be kind to put a like to this post.
While you are doing DataBase quering normally you need to have a Primary key
for the table. Then it should be unique. Therefore show how to get first ID for
empty table and next ID for not empty tables in Oracle.
SELECT decode( MAX(cast(ID as integer)),null,0,MAX(cast(ID as integer))) INTO next_id FROM TABLE;
next_id := next_id+1;
-- here ID means Primary key number colum
-- table means your table
If you got some thing from this please be kind to put a like to this post.
Comments
Post a Comment