Error in query INSERT INTO

1

I'm new using Oracle SQL Developer and I'm trying to make the query run but this is a bug, see the photo.

    
asked by anonymous 25.11.2017 / 22:29

1 answer

2

First you need to check if the SEQUENCE of the PERSON table already exists. It is interesting to use a SEQUENCE to generate the values for the primary key.

  

Use the CREATE SEQUENCE statement to create a string, which is a database object from which multiple users can generate unique integers. You can use strings to automatically generate primary key values. [ SQL Language Reference, 2016 , 1,173 p.]

     

When a sequence number is generated, the sequence is incremented regardless of whether the transaction is compromised or rolled back. If two users simultaneously increment the same sequence, the sequence numbers that each user acquires may have gaps because the sequence numbers are being generated by the other user. A user can never acquire the sequence number generated by another user. After a sequence value is generated by a user, that user can continue to access that value regardless of whether the sequence is incremented by another user. [ SQL Language Reference, 2016 , 1,173 p.]

CREATE SEQUENCE person_seq 
    START WITH 1000 
    INCREMENT BY 2
    NOCACHE
    NOCYCLE;

So you can test:

SELECT person_seq.nextval FROM DUAL;

Now yes you can perform the insert into the table:

INSERT INTO PERSON (PERSON_ID, PERSON_NAME, AGE)
    VALUES (person_seq.nextval,'Diana','28');

NOTE : Important to understand that there are many ways to do this. Create a trigger and bind the SEQUENCE with the INSERT and / or UPDATE actions of the table.

Reference : [SQL Language Reference, 2016], Copyright © 1996, 2016, Oracle and / or its affiliates, Oracle Database SQL Language Reference : 11g Release 2 (11.2). Available in: < link & gt ;. Access on 25 Nov. 2017
[Java Developer's Guide, 2009], Copyright © 1996, 2016, Oracle and / or its affiliates, Oracle Database Java Developer's Guide :, 11g Release 1 (11.1) B31225-05. Available in: < link & gt ;. Accessed on 25 Nov. 2017

    
25.11.2017 / 23:43