Header Ads Widget

Module 05: Writing Control Structures


Writing Control Structures


01. Write down about IF Statement.

The structure of the PL/SQL IF statement is similar to the structure of IF statements in other procedural languages. It allows PL/SQL to perform actions selectively based on conditions.

Syntax:

IF condition THEN

statements;

[ELSIF condition THEN 

statements;]

[ELSE 

statements;]

END IF;

In the syntax:

Condition Is a Boolean variable or expression that returns TRUE, FALSE, or NULL THEN Introduces a clause that associates the Boolean expression with the sequence of statements that follows it

Statements Can be one or more PL/SQL or SQL statements. The statements in the THEN clause are executed only if the condition in the associated IF clause evaluates to TRUE.

ELSIF       Is a keyword that introduces a Boolean expression ELSE Introduces the default clause that is executed if and only if none of theearlier predicates (introduced by IF and ELSIF) are TRUE

END IF Marks the end of an IF statement


For example:

a. Simple IF Statement

DECLARE

myage number:=31;

BEGIN

IF myage< 11

THEN

DBMS_OUTPUT.PUT_LINE(' I am a child ');

END IF;

END;

/


02. What is Loops? What are the types of Loops?

Loops repeat a statement or sequence of statements multiple times.

There are three loop types:

a. Basic loop that performs repetitive actions without overall conditions.

b. FOR loops that perform iterative actions based on a count.

c. WHILE loops that perform iterative actions based on a condition.


03. How to you work with Basic Loops?

A basic loop allows execution of its statements at least once, even if the EXIT condition is already met upon entering the loop. Without the EXIT statement, the loop would be infinite.


04. How to you work with WHILE Loops?

The WHILE loop to repeat statements while a condition is TRUE.


05. How to you work with FOR Loops?

FOR Loops:

a. A FOR loops to shortcut the test for the number of iterations.

b. Do not declare the counter; it is declared implicitly.


Post a Comment

0 Comments