[go: up one dir, main page]

0% found this document useful (0 votes)
40 views3 pages

PLSQL Control Statements

Control statements in PL/SQL dictate the logical flow of a program and are categorized into three types: Conditional Control (IF statements), Iterative Control (loops), and Sequential Control (GOTO statement). Conditional Control allows decision-making based on conditions, Iterative Control includes different types of loops for repeated execution, and Sequential Control is used for jumping to labeled statements, though it's generally avoided for readability. Examples are provided for each type to illustrate their usage.

Uploaded by

alekhayareddy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

PLSQL Control Statements

Control statements in PL/SQL dictate the logical flow of a program and are categorized into three types: Conditional Control (IF statements), Iterative Control (loops), and Sequential Control (GOTO statement). Conditional Control allows decision-making based on conditions, Iterative Control includes different types of loops for repeated execution, and Sequential Control is used for jumping to labeled statements, though it's generally avoided for readability. Examples are provided for each type to illustrate their usage.

Uploaded by

alekhayareddy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Control Statements in PL/SQL

Control statements in PL/SQL determine the logical flow of a program. There are three main types:

1. Conditional Control: IF Statements

These are used to make decisions based on certain conditions.

Syntax:

IF condition THEN

-- statements

ELSIF another_condition THEN

-- statements

ELSE

-- statements

END IF;

Example:

IF salary > 10000 THEN

DBMS_OUTPUT.PUT_LINE('High salary');

ELSE

DBMS_OUTPUT.PUT_LINE('Low salary');

END IF;

2. Iterative Control: Loops

PL/SQL supports three types of loops:


a. Basic LOOP

LOOP

-- statements

EXIT WHEN condition;

END LOOP;

b. WHILE LOOP

WHILE condition LOOP

-- statements

END LOOP;

c. FOR LOOP

FOR counter IN [REVERSE] start..end LOOP

-- statements

END LOOP;

Example:

FOR i IN 1..5 LOOP

DBMS_OUTPUT.PUT_LINE(i);

END LOOP;

3. Sequential Control: GOTO Statement

Used to jump to a labeled statement. Avoided in practice for readability.

Example:

BEGIN

GOTO skip;
DBMS_OUTPUT.PUT_LINE('This line is skipped');

<<skip>>

DBMS_OUTPUT.PUT_LINE('Jumped here');

END;

You might also like