0% found this document useful (0 votes)
40 views

Packages - List No 15

This document demonstrates how to create and use a PL/SQL package. It defines a package called pack1 with a procedure called f_pow that calculates powers and a function called f_fact that calculates factorials. It shows creating the package specification and body, executing the f_pow procedure, and calling the f_fact function from an anonymous block to calculate and display the factorial of 5.

Uploaded by

virusyadav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Packages - List No 15

This document demonstrates how to create and use a PL/SQL package. It defines a package called pack1 with a procedure called f_pow that calculates powers and a function called f_fact that calculates factorials. It shows creating the package specification and body, executing the f_pow procedure, and calling the f_fact function from an anonymous block to calculate and display the factorial of 5.

Uploaded by

virusyadav
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

List no 15):- To study packages.

Roll no ------ 06 SQL> set serveroutput on; SQL> create or replace package pack1 is 2 procedure f_pow(b number, p number); 3 function f_fact(n number) return number; 4 end; 5 / Package created. SQL> create or replace package body pack1 is 2 procedure f_pow(b number, p number) is 3 rs number(6); 4 ctr number(3); 5 begin 6 rs:=1; 7 for ctr in 1..p 8 loop 9 rs:=rs*b; 10 end loop; 11 dbms_output.put_line('Power is '||rs); 12 end; 13 function f_fact(n number) return number is 14 ft number(8); 15 ctr number(2); 16 begin 17 ft:=1; 18 for ctr in 1..n 19 loop 20 ft:=ft*ctr; 21 end loop; 22 return(ft); 23 end; 24 end; 25 / Package body created. SQL> exec pack1.f_pow(2,3);

Power is 8 SQL> declare 2 no number(2); 3 ans number(8); 4 begin 5 no:=&no; 6 ans:=pack1.f_fact(no); 7 dbms_output.put_line('factorial of entered no is '||ans); 8 end; 9 / Enter value for no: 5 old 5: no:=&no; new 5: no:=5; factorial of entered no is 120 PL/SQL procedure successfully completed.

You might also like