0% found this document useful (0 votes)
7 views

Controlstatements in PLSQL

Uploaded by

Dhavan Ravuri
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Controlstatements in PLSQL

Uploaded by

Dhavan Ravuri
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Control statement:

* Decision making in PL/SQL


* Used to test a condition and execute the given block
* PL/SQL provides the following control statement

1. If statement

if statments:
* It is branching statement to control flow of execution.
* it has three forms
1.if then .. end if;
2.if then else end if
3. if then elsif then end if;

1.if then .. end if:


* very simple form if statement
* it has one condition with one block
* the block is executed only when condition is true.
syntax:
if condition then
statements;
end if;
ex:
declare
eid number;
begin
eid:=&empid;
if eid=10 then
update emp set salary=salary+2300 where empid=eid;
end if;
end;
2.if then.. else.. end if:
* two way decision making statement
* has one condition with two blocks
* If condition is true it will execute true block otherwise execute false block
syntax:
if condition then
Tstatements;
else
Fstatements
end if;
ex:
declare
a number;
b number;
begin
a:=&a;
b:=&b;
if a> b then
dbms_output.put_line('A is big');
else
dbms_output.put_line('B is big');
end if;
end;

if then elsif else end if:


* N way decision making statement
* It has n condition with n blocks
* you can choose one block from n blocks
* also called as If Else Ladder

syn:
if condition then
statements;
elsif condition then
statements;
elsif condition then
statements;
else
statements;
end if;

ex:
declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=&c;
if a>b and a>c then
dbms_output.put_line('a is big');
elsif b>c then
dbms_output.put_line('b is big');
else
dbms_output.put_line('c is big');
end if;
end;

You might also like