How to paste conditionally in Oracle?

I read here that the syntax is as follows:

INSERT WHEN ([Condition]) THEN INTO [TableName] ([ColumnName]) VALUES ([VALUES]) ELSE INTO [TableName] ([ColumnName]) VALUES ([VALUES]) SELECT [ColumnName] FROM [TableName]; 

But I do not want to provide values โ€‹โ€‹from another table. I just want to type them, so I have:

 INSERT WHEN EXISTS (SELECT 1 FROM FOO WHERE NAME = 'JOE') THEN INTO BAR (NAME, AGE) VALUES ('JOE', 50) 

and this throws an exception: ORA-00928: missing SELECT keyword.

I want to perform an insertion if the given value is found in another table.

+5
source share
2 answers

using the select function also works. but there is a problem with the keywords values

 INSERT WHEN EXISTS (SELECT 1 FROM FOO WHERE NAME = 'JOE') THEN INTO BAR (NAME, AGE) SELECT 'JOE', 50 FROM DUAL 
+4
source

So, I found an indirect way here , and the solution for my question would be:

 INSERT INTO BAR (NAME, AGE) SELECT 'JOE', 50 FROM DUAL WHERE EXISTS (SELECT 1 FROM FOO WHERE NAME = 'JOE') 

but that doesnโ€™t explain why I should use the SELECT in INSERT WHEN

+1
source

Source: https://habr.com/ru/post/1263318/


All Articles