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

Manual No 14

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)
7 views3 pages

Manual No 14

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/ 3

Submitted By: SWEN221101044

Lab 14:Functions in PL/SQL

Objection
Introduction of functions in PL/SQL

Introduction
Write a Function to check the given number is prime or not.

FUNCTION DEFINITION :

CREATE or REPLACE FUNCTION isprime(num in number) RETURN


number IS
temp NUMBER;
BEGIN
temp:=num;
FOR itr IN 2..(num-1)
LOOP
IF (mod(temp,itr)=0) THEN
return 1;
END IF;
END LOOP;
return 0;
END;
/

PL/SQL BLOCK TO CALL THE FUNCTION:

DECLARE
given_number NUMBER;
prime_check NUMBER;
BEGIN
given_number:=&given_number;
prime_check:=isprime(given_number);
IF prime_check=0 THEN
dbms_output.put_line(’NUMBER IS PRIME’);

60
61

ELSE
dbms_output.put_line(’NUMBER IS NOT PRIME’);
END IF;
END;
/

Output

Write pl./sql code in Function for Factorialnumber.

(a) set serveroutput on;

create or replace Function FunFact(a number) return number IS


f number(4):=1;
begin
for i in 1..a
loop
f:=f*i;
end loop;
return f;
end;
/
(b) set serveroutput on;
Declare
n number(2):=&n;
r number(4);
Begin
r:=FunFact(n);
dbms_output.put_line(’factorial of’||n||’is:’||r);
end;
/

Output

You might also like