oracle

Monday, 1 May 2017

PL/SQL: IF ELSE OR IF THEN ELSE STATEMENT

If then else statement executes sequence of statements only when the condition is evaluated to be true.



Syntax:
If condition then
statement(s);
else
statement(s);
end if;
statement(s);
end;
/

Example:
declare
v_num number:= &Enter_a_Number;
begin
if mod(v_num,2)=0 then
dbms_output.put_line('You Entered an Even number '||v_num);
  else
  dbms_output.put_line('You Entered an Odd number '||v_num);
end if;
dbms_output.put_line('Muhammad Talah Zubair');
end;

/
give input 10

Result:
You Entered an Even number 10
Muhammad Talah Zubair

Now check it again, by providing odd number as input , and check out the result.

Example:
declare
v_num number:= &Enter_a_Number;
begin
if mod(v_num,2)=0 then
dbms_output.put_line('You Entered an Even number '||v_num);
  else
  dbms_output.put_line('You Entered an Odd number '||v_num);
end if;
dbms_output.put_line('Muhammad Talah Zubair');
end;

/
give input 11 

Result:
You Entered an Odd number 11

Muhammad Talah Zubair

No comments:

Post a Comment