How to insert rows in auto increment oracle table

John 190 Reputation points
2023-05-18T21:06:15.23+00:00

Hi,

I need to insert rows into an oracle table but the oracle table has auto increment sequence.

so one column definition is like this:-

"ID" NUMBER(10,0) DEFAULT "SC1"."DAT1_CTR_SEQ"."NEXTVAL" NOT NULL ENABLE

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,528 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vahid Ghafarpour 17,870 Reputation points
    2024-01-02T01:58:58.9+00:00

    Thanks for posting your question in the Microsoft Q&A forum.
    Did you try this command?

    INSERT INTO your_table_name (ID, other_column1, other_column2) VALUES ("SC1"."DAT1_CTR_SEQ"."NEXTVAL", 'value1', 'value2');
    

    Also, you can use the following command to return the inserted ID.

    DECLARE
      v_id NUMBER;
    BEGIN
      INSERT INTO your_table_name (ID, other_column1, other_column2)
      VALUES ("SC1"."DAT1_CTR_SEQ"."NEXTVAL", 'value1', 'value2')
      RETURNING ID INTO v_id;
    
      DBMS_OUTPUT.PUT_LINE('Inserted ID: ' || v_id);
    END;
    
    

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **

    0 comments No comments

0 additional answers

Sort by: Most helpful