Search code examples
c#.netoraclesequenceodp.net

How to Retrieve an Oracle Sequence value?


I need to retrieve a VarChar sequence value. How is that done using C# and Oracle's ODP components?

A less-specific answer might help, too (e.g., how it's done in VB or how it's done using a different component set).


Solution

  • To get back a string value representing a sequence value you'll need to convert the sequence's NEXTVAL to a character string using TO_CHAR; something like

    SELECT TO_CHAR(MY_SCHEMA.MY_SEQUENCE.NEXTVAL, 'TM9') FROM DUAL
    

    Don't know C# well enough to advise on that, but you can probably work it out from there.

    Share and enjoy.