ID being created and not starting with 0 - Oracle 11g

Asked

Viewed 45 times

2

I am studying Database, using Oracle 11g and making the tables in SQLPLUS. I create the table:

CREATE TABLE COMPRAS (ID NUMBER PRIMARY KEY, VALOR NUMBER, DATA DATE, 
OBSERVACOES VARCHAR2(30), RECEBIDO CHAR CHECK (RECEBIDO IN (0,1)));

And right after, I create a sequence:

CREATE SEQUENCE ID_SEQ;

With this, I will enter the data with this command:

INSERT INTO COMPRAS (ID, VALOR, DATA, OBSERVACOES, RECEBIDO) VALUES 
(ID_SEQ.NEXTVAL, 100, ’12-MAY-2007’, ‘Compras de Maio’, ‘1’);

And to see the data inserted in the table, I rotate:

SELECT * FROM COMPRAS;

inserir a descrição da imagem aqui

  • There were probably two errors before you hit the INSERT command. Even when an error occurs the sequence is updated and so there may be holes.

  • Hello @Vagner, do not change your question to indicate that you have managed to find a solution, I am happy to know that you want to help others with the same problem, in which case the best option is to answer your own question, but later the system will release you to accept your own answer. Tip: how you found the solution in the documentation is worth you adding the documentation link in your reply. = D --- I will reverse your edit, you can see it here

1 answer

1


The solution that solves this problem is that the documentation of Oracle 11g is different from the others by the way, giving a search in the documentation I found that it is not only necessary to create the sequence with this command below:

CREATE SEQUENCE ID_SEQ;

In the documentation of Oracle 11g, it is necessary to do so, follows below:

CREATE SEQUENCE ID_SEQ START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.