0% found this document useful (0 votes)
3 views5 pages

5TH PRIYA

Uploaded by

23cb035
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)
3 views5 pages

5TH PRIYA

Uploaded by

23cb035
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/ 5

SHENBAGAPRIYA N 710723244049

EX NO:5 IMPLEMENTATION OF LOOPING IN QUERIES

DATE:

AIM:

To write the PL/SQL query to illustrate the concept of looping.

ALGORITHM:
Step 1: Start.
Step 2: Open SQL environment.
Step 3: Write the looping logic.
Step 4: Use the Looping in Queries.
Step 5: Execute and verify results.
Step 6: Stop.

QUERY:

a) PL/SQL Query for EXIT loop:


SYNTAX:
LOOP
statements;
EXIT;
{or EXIT WHEN condition;}
END LOOP;

EXAMPLE:
DECLARE
i NUMBER :=1; BEGIN
LOOP
EXIT WHEN i>10;
DBMS_OUTPUT.PUT_LINE(i); i:=i+1;
END LOOP;
END;
/

22UCS402 DATABASE MANAGEMENT SYSTEMS LABORATORY


SHENBAGAPRIYA N 710723244049

b) PL/SQL Query for IF_THEN_ELSE Statement:

SYNTAX:

IF Condition THEN
{…statements to execute when condition is TRUE…} ELSE
{…statements to execute when condition is FALSE…} END IF;

EXAMPLE:
SET SERVEROUTPUT ON
DECLARE
num NUMBER;=12;
BEGIN
IF MOD(num,2) = 0 THEN
DBMS_OUTPUT.PUT_LINE(‘The number’||num|| ‘is even’); ELSE
DBMS_OUTPUT.PUT_LINE(‘The number’||num|| ‘is odd’); END
IF;
END;

22UCS402 DATABASE MANAGEMENT SYSTEMS LABORATORY


SHENBAGAPRIYA N 710723244049

c)PL/SQL Query for FOR loop


SYNTAX:

FOR counter IN initial_value .. final_value LOOP LOOP


statements;

END LOOP;

PL/SQL query to print factorial of given number.

EXAMPLE:

DECLARE

num INT := 5;
factorial_result NUMBER := 1; i
INT;

BEGIN

FOR i IN 1..num LOOP


factorial_result := factorial_result * i; END
LOOP;
DBMS_OUTPUT.PUT_LINE('The factorial of '|| num || ' is ' || factorial_result);
END;

22UCS402 DATABASE MANAGEMENT SYSTEMS LABORATORY


SHENBAGAPRIYA N 710723244049

d)PL/SQL Query for WHILE loop:

SYNTAX:
WHILE <condition>
LOOP statements;

END LOOP;

EXAMPLE:
SET SERVEROUTPUT ON;
DECLARE
counter INT := 10; BEGIN
WHILE counter >= 1 LOOP
DBMS_OUTPUT.PUT_LINE(counter); counter :=
counter - 1;
END LOOP;
END;
/

22UCS402 DATABASE MANAGEMENT SYSTEMS LABORATORY


SHENBAGAPRIYA N 710723244049

RESULT:

Thus the SQL queries with functions has been written & ran successfully with given example.

22UCS402 DATABASE MANAGEMENT SYSTEMS LABORATORY

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy