Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Oracle uses sequences as for his identity columns, if we may say so.</p> <p>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.</p> <p>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.</p> <p>Here's an instance:</p> <pre><code>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; </code></pre> <p>If you want to manage the auto-increment yourself, here's how:</p> <pre><code>INSERT INTO my_table ( id_my_table, description ) VALUES (my_table_seq.NEXTVAL, "Some description"); COMMIT; </code></pre> <p>On the other hand, if you wish not to care about the PRIMARY KEY increment, you may proceed with a trigger.</p> <pre><code>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; </code></pre> <p>Then, when you're inserting, you simply type the INSERT statement as follows:</p> <pre><code>INSERT INTO my_table (description) VALUES ("Some other description"); COMMIT; </code></pre> <p>After an INSERT, I guess you'll want to </p> <pre><code>SELECT my_table_seq.CURRVAL </code></pre> <p>or something like this to select the actual value of your sequence.</p> <p>Here are some links to help:</p> <p><a href="http://www.orafaq.com/wiki/Sequence" rel="noreferrer">http://www.orafaq.com/wiki/Sequence</a></p> <p><a href="http://www.orafaq.com/wiki/AutoNumber_and_Identity_columns" rel="noreferrer">http://www.orafaq.com/wiki/AutoNumber_and_Identity_columns</a></p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload