The only way I know is what you don't want.
-- find the last `sno` value; let's presume it returns 5
select max(sno) from that_table;
-- create a sequence which starts with max + 1 (i.e. 6):
create sequence seq start with 6;
-- create a trigger which populates `sno`:
create or replace trigger trg_bi_tab
before insert on that_table
for each row
begin
:new.sno := seq.nextval;
end;
/
Note that sequences aren't gapless, which means that it might (and will, sooner or later) produce gaps.
If you badly insist on continuing the sno
sequence, then it is literally MAX + 1
. Can you do that? Sure, but that's a bad idea because you might (and will) get duplicates whenever two (or more) users fetch the same MAX value; only the first one who commits will store that value - all other users will create duplicates (and, possibly, violate uniqueness if sno
column is supposed to be unique).
Yes, you could lock the table until the first user - who is working on that table - does the job and commits, but that's even worse because in a multi-user environment you'll have many not-that-happy users (who are waiting ... and waiting ...).
Or, you could create your own "sequence" - a table that holds the next value. You'd calculate it with an autonomous transaction function.
But, why would you want to do anything of that? Create a sequence that starts with max + 1
and let Oracle do the rest.