insert into OPT (email, campaign_id) values('[email protected]',100) where not exists( select * from OPT where (email ="[email protected]" and campaign_id =100)) ;
Error report: SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" *Cause:
*Action:
how to insert a new row if it doesn't exists in Oracle?
There are three ways you can perform an “insert if not exists” query in MySQL: Using the INSERT IGNORE statement. Using the ON DUPLICATE KEY UPDATE clause. Or using the REPLACE statement.
The INSERT command can also take the values directly from another table using 'SELECT' statement rather than giving the values for each column. Through 'SELECT' statement, we can insert as many rows as the base table contains. Syntax: BEGIN INSERT INTO <table_name>(<column1 >,<column2>,...
The simplest way to create an Oracle INSERT query to list the values using the VALUES keyword. For example: INSERT INTO suppliers (supplier_id, supplier_name) VALUES (5000, 'Apple'); This Oracle INSERT statement would result in one record being inserted into the suppliers table.
insert into OPT (email, campaign_id) select '[email protected]',100 from dual where not exists(select * from OPT where (email ='[email protected]' and campaign_id =100));
The correct way to insert something (in Oracle) based on another record already existing is by using the MERGE statement.
Please note that this question has already been answered here on SO:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With