You'll want to generate a "sequence", setting an initial number and an increment.

create sequence seq_name start with 1 increment by 1 maxvalue 999999 nocycle cache 20;

then you'll do something similar to this:

INSERT INTO table_name ( id_no, col1, col2 ) values ( seq_name.NEXTVAL, '$col1', '$col2' )

if you have few inserts and want to not have skipped sequence numbers, then avoid using a cache, it tends to cause "gaps" (at least in our environment)

good luck!

PS: wait for the insert to get the nextval, then display it post-insert. not before, or you'll get into trouble with non-uniqueness, which is what sequences are made to avoid :-)


In reply to Re: Last ID by wardk
in thread Last ID by qball

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.