You can keep the flow the same, but the actual SQL will be different.

In SQLite:

insert into table ... select last_insert_rowid();
In Oracle, assuming you have setup a trigger to emulate the auto_increment feature:
insert into table ... select table_seq.currval from dual;
Note that you have to name your sequence predictably based on the table name to do that. We just append "_seq" to the table name to get the sequence name.

If you *really* want to be clever, you could set up an oracle package to contain a global session variable, and then make all your auto_increment-emulation triggers update that variable. Then you can write a last_insert_rowid() function to return that value. But you still need the "from dual" in oracle, so the sql is still different.


In reply to Re: Sequences, last_insert_id, SQLite, and Oracle by sharkey
in thread Sequences, last_insert_id, SQLite, and Oracle by gaal

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.