Less
Copyright © 2004, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to do
the following:
• Identify the uses and typesof control structures
• Construct an IF statement
• Use CASE statements and CASE expressions
• Construct and identify different loop statements
• Make use of guidelines while using the conditionalcontrol structures
5-2
Copyright © 2004, Oracle. All rights reserved.
Controlling Flow of Execution
for
loop
while
5-3
Copyright © 2004, Oracle. All rights reserved.
IFStatements
Syntax:
IF condition THEN
statements;
[ELSIF condition THEN
statements;]
[ELSE
statements;]
END IF;
5-4
Copyright © 2004, Oracle. All rights reserved.
IF Statements
5-5Copyright © 2004, Oracle. All rights reserved.
Simple IF Statement
DECLARE
myage number:=31;
BEGIN
IF myage < 11
THEN
DBMS_OUTPUT.PUT_LINE(' I am a child ');
END IF;
END;
/
5-6Copyright © 2004, Oracle. All rights reserved.
IF THEN ELSE Statement
SET SERVEROUTPUT ON
DECLARE
myage number:=31;
BEGIN
IF myage < 11
THEN
DBMS_OUTPUT.PUT_LINE(' I am a child ');
ELSEDBMS_OUTPUT.PUT_LINE(' I am not a child ');
END IF;
END;
/
5-7
Copyright © 2004, Oracle. All rights reserved.
IF ELSIF ELSE Clause
DECLARE
myage number:=31;
BEGIN
IF myage < 11THEN
DBMS_OUTPUT.PUT_LINE(' I
ELSIF myage < 20
THEN
DBMS_OUTPUT.PUT_LINE(' I
ELSIF myage < 30
THEN
DBMS_OUTPUT.PUT_LINE(' I
ELSIF myage < 40
THEN
DBMS_OUTPUT.PUT_LINE(' I
ELSEDBMS_OUTPUT.PUT_LINE(' I am
END IF;
END;
/
5-8
am a child ');
am young ');
am in my twenties');
am in my thirties');
always young ');
Copyright © 2004, Oracle. All rights reserved.
NULLValues in IF Statements
DECLARE
myage number;
BEGIN
IF myage < 11
THEN
DBMS_OUTPUT.PUT_LINE(' I am a child ');
ELSE
DBMS_OUTPUT.PUT_LINE(' I am not a child ');
END IF;
END;
/
5-9...
Regístrate para leer el documento completo.