Why is my SQL failing? (ORA-00933: SQL command not

2019-08-30 06:58发布

问题:

Why is my SQL failing? I think it s formatted correctly, but it throws an error at me.

    INSERT INTO NBOT_USERS
       (ID,LAST_NAME,FIRST_NAME)
    VALUES
       (1002, 'Smith', 'John')
    WHERE 1002 NOT IN (SELECT IT_ID FROM NBOT_USERS);

回答1:

Inserting Values with a Subquery: Example

INSERT INTO bonuses
   SELECT employee_id, salary*1.1 
   FROM employees
   WHERE commission_pct > 0.25 * salary;

With your schema:

INSERT INTO NBOT_USERS (ID,LAST_NAME,FIRST_NAME)
Select 1002, 'Smith', 'John' 
  From dual
  WHERE 1002 NOT IN (SELECT  FROM NBOT_USERS);


回答2:

Insert queries do not have where clauses, unless you're doing INSERT ... SELECT FROM, in which case there can be a where clause in the SELECT portion.