Kolya Kolya - 22 days ago 5
SQL Question

Getting "missing right parenthesis", Oracle DB, Java

I'm getting a right parenthesis SQL error (ORA-00907) in the following code:

sql = "INSERT INTO Usuarios" +
"(User_ID, Usuario, Contrasena)" +
"SELECT (1, 'Administrador', 'passA')"
+ "FROM DUAL"
+ "WHERE NOT EXISTS (SELECT NULL FROM Usuarios WHERE User_ID = 1)";


Is there really a mistake in that sentence? If so, can you help me determine where exactly is it?

Answer

Yes, there is.

Here's what the SQL server sees:

INSERT INTO Usuarios(User_ID, Usuario, Contrasena)SELECT (1, 'Administrador', 'passA')FROM DUALWHERE NOT EXISTS (SELECT NULL FROM Usuarios WHERE User_ID = 1)

I'll leave you to figure it out from there.