I created a very simple table:
CREATE TABLE TMP ("ID" VARCHAR2(20 BYTE));
Then tried to do this:
DECLARE
whatever varchar2(20) := :bananas;
BEGIN
MERGE INTO tmp t USING
(SELECT whatever AS this_id FROM DUAL) d
ON (t.id = d.this_id)
WHEN NOT MATCHED THEN
INSERT (id) VALUES (d.this_id);
END;
And then enter binds
And get this error:
Error starting at line : 1 in command -
DECLARE
whatever varchar2(20) := :bananas;
BEGIN
MERGE INTO tmp2 t USING
(SELECT whatever AS this_id FROM DUAL) d
ON (t.id = d.this_id)
WHEN NOT MATCHED THEN
INSERT (id) VALUES (d.this_id);
END;
Error report -
Missing defines
I've had no luck figuring out what it wants. If I replace ':bananas' with a value like 'a' it works, but not when I use a variable and bind the value. Anyone know whats wrong with my query? Thanks.
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
"CORE 11.2.0.4.0 Production"
TNS for IBM/AIX RISC System/6000: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
edit: I've just noticed that the error is not preventing the data from being merged correctly... The error is still concerning though
It (<>) is a function that is used to compare values in database table. != (Not equal to) functions the same as the <> (Not equal to) comparison operator.
ORA-00906: missing left parenthesis Cause: A required left parenthesis has been omitted. Certain commands, such as CREATE TABLE, CREATE CLUSTER, and INSERT, require a list of items enclosed in parentheses. Parentheses also are required around subqueries in WHERE clauses and in UPDATE table SET column = (SELECT...)
not in can also take literal values whereas not exists need a query to compare the results with. EDIT: not exists could be good to use because it can join with the outer query & can lead to usage of index, if the criteria uses column that is indexed.
I would probable skip the DECLARE section all together and use everywhere :bananas instead of whatever. After BEGIN put :bananas := :bananas; and you'll get no error. Good luck.
Try adding a slash after the statement on a line of its own. Then highlight the whole block and press F5.
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