Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 340281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:36:05+00:00 2026-05-12T10:36:05+00:00

I know that in Oracle I can get the generated id (or any other

  • 0

I know that in Oracle I can get the generated id (or any other column) from an inserted row as an output parameter.
Ex:

insert into foo values('foo','bar') returning id into :myOutputParameter

Is there a way to do the same, but using ExecuteScalar instead of ExecuteNonQuery?

I don’t want to use output parameters or stored procedures.

ps: I’m using Oracle, not sql server!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:36:06+00:00Added an answer on May 12, 2026 at 10:36 am

    Oracle uses sequences as for his identity columns, if we may say so.

    If you have set a sequence for your table primary key, you also have to write a trigger that will insert the Sequence.NextValue or so into your primary key field.

    Assuming that you are already familiar with this concept, simply query your sequence, then you will get your answer. What is very practiced in Oracle is to make yourself a function which will return an INT, then within your function, you perform your INSERT. Assuming that you have setup your trigger correctly, you will then be able to return the value of your sequence by querying it.

    Here’s an instance:

    CREATE TABLE my_table (
        id_my_table INT PRIMARY KEY
        description VARCHAR2(100) NOT NULL
    )
    
    CREATE SEQUENCE my_table_seq
       MINVALUE 1
       MAXVALUE 1000
       START WITH 1
       INCREMENT BY 2
       CACHE 5;
    

    If you want to manage the auto-increment yourself, here’s how:

    INSERT INTO my_table (
        id_my_table,
        description
    ) VALUES (my_table_seq.NEXTVAL, "Some description");
    COMMIT;
    

    On the other hand, if you wish not to care about the PRIMARY KEY increment, you may proceed with a trigger.

    CREATE OR REPLACE TRIGGER my_table_insert_trg
        BEFORE INSERT ON my_table FOR EACH ROW
    BEGIN
        SELECT my_table_seq.NEXTVAL INTO :NEW.id_my_table FROM DUAL;
    END;
    

    Then, when you’re inserting, you simply type the INSERT statement as follows:

    INSERT INTO my_table (description) VALUES ("Some other description");
    COMMIT;
    

    After an INSERT, I guess you’ll want to

    SELECT my_table_seq.CURRVAL
    

    or something like this to select the actual value of your sequence.

    Here are some links to help:

    http://www.orafaq.com/wiki/Sequence

    http://www.orafaq.com/wiki/AutoNumber_and_Identity_columns

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When writing a row-level trigger in Oracle, I know that you can use the
I know that you can insert multiple rows at once, is there a way
In Oracle, this returns 03/01/2010. That does not make sense to me. Anybody know
I know that I can do something like $int = (int)99; //(int) has a
I know that default cron's behavior is to send normal and error output to
I know that the MsNLB can be configured to user mulitcast with IGMP. However,
I'm looking for a tool that can watch database(mysql and oracle) for changes. When
I need to get some sensitive data from an Oracle server to a SQL
As mentioned in title. I wanna know that does SQL Server can partially execute
Is there a SQL query I can run (or some other way) that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.