ORACLE : Assignment and Checking in same statement

Viewed 70

In Oracle PL/SQL, can I do something like this :

if ( ( i = a ) = 3 )

that is - set variable i to a and then check if it is 3.

thanks

2 Answers
set serveroutput on

declare
    i   number;
    j   number;
begin
    i   := 3;
    j   := 3;
    if ( ( i = j ) = 3 ) then
        dbms_output.put_line('Success');
    else
        dbms_output.put_line('No luck');
    end if;

end;

So I tried above code and below is the error I got.

PLS-00306: wrong number or types of arguments in call to '='

So I understand that we can't do assignment and checking is same statement.

Yes, of course:

declare
  a number := 3;
  i number;
begin
  i := a; if i = 3 then dbms_output.put_line('i am so smrt'); end if;
end;

:)

Related