Reputation: 13
I am using oracle SQL developer and am trying to run a query with an if statement in it.
I have defined a variable and assigned a value to it.
define
var buyer varchar2(1)
/* define variable values */
exec :buyer := 'Yep'
if :buyer = 'Yep' then
begin
dbms_output.put_line('Yep');
else
dbms_output.put_line('Nope');
end;
However, when I run the script, I get an error message stating that IF is an unknown command.
Error starting at line : 8 in command -
if :buyer = 'Yep' then
Error report -
Unknown Command
Any advice is greatly appreciated.
Upvotes: 1
Views: 3321
Reputation: 990
You have to define a DECLARE-BEGIN-END block to run IF-ELSIF-ELSE-END conditions. Based on your sample code, I'm assuming this is what you would like to do.
DECLARE
buyer VARCHAR2(3) := 'Yep';
BEGIN
IF ( buyer = 'Yep' ) THEN
dbms_output.put_line('Yep' );
ELSE
dbms_output.put_line('Nope');
END IF;
END;
/
You could run this as a script in sql developer. HTH!
Upvotes: 1
Reputation: 3436
Look up the PLSQL Syntax:
DECLARE
variable type;
BEGIN
IF variable = 'test'
THEN
DBMS_OUTPUT.PUT_LINE('J');
ELSE
DBMS_OUTPUT.PUT_LINE('N');
END IF;
END;
/
Upvotes: 1