0% found this document useful (0 votes)
13 views4 pages

Manual No 13

Uploaded by

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

Manual No 13

Uploaded by

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

Submitted By:

SWEN221101044
Chapter 13

Lab 13:Stored procedures


in PL/SQL

Objectives

Creating stored procedures and functions

Introduction

Write PL/SQL code in Procedure to find Reverse number

CREATE OR REPLACE PROCEDURE REVNUM(NUM NUMBER)


IS
REV
INTEGER(6);
NUM1
NUMBER(6);
BEGIN
NUM1:=NUM;
REV:=0;
WHILE NUM1>0
LOOP
REV:=REV*10+MOD(NUM1,10);
NUM1:=TRUNC(NUM1/10);
END LOOP;
DBMS_OUTPUT.PUT_LINE(REV);
END REVNUM;
/

Output
57
58 Lab 13:Stored procedures in PL/SQL

Write PL/SQL code in Procedure to find Factorial of a given number by


using call proce- dure.

a) CREATE OR REPLACE PROCEDURE FACT(A IN NUMBER,B OUT NUMBER) IS


F NUMBER(4):=1;
BEGIN
FOR I IN 1..A
LOOP
F:=F*I;
END LOOP;
B:=F;
END;
/
b) DECLARE
X NUMBER(4):=&X;
Y NUMBER;
BEGIN
FACT(X,Y);
DBMS_OUTPUT.PUT_LINE(’FACTORIAL OF’ ||’ ’||X||’ ’ ||’IS’||’ ’||Y);
END;
/

Output

Write a Procedure to check the given number is prime or not by using call
procedure.

PROCEDURE DEFINITION:

CREATE or REPLACE PROCEDURE isprimepro(num in number,chec out number) IS


temp NUMBER;
BEGIN
temp:=num;
FOR itr IN 2..(num-1)
LOOP
IF(mod(num,itr)=0) THEN
59

/
chec:=1;
END IF;
END; END LOOP;

PL/SQL BLOCK TO CALL THE PROCEDURE:

DECLARE
chec NUMBER;
given_number NUMBER;
BEGIN
given_number:=&given_number;
isprimepro(given_number,chec);
IF chec=1 THEN
dbms_output.put_line(’number is not prime’);
ELSE
dbms_output.put_line(’number is prime’);
END IF;
END;
/

Output

You might also like