Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2
--function created to calculate cube of a number
Create or replace function fn_cube(p number)
return number is y number; begin y:=p*p*p; return y; end;
--calling the function fn_cube() from dbms_output
begin dbms_output.put_line(fn_cube(2)); end;
--calling the function fn_cube()
declare c number:=0; begin c:=fn_cube(2); dbms_output.put_line('cube is='||c); end;
output: Statement processed. cube is=8
--function created to count the number of employees,no parameters to function
Create or replace function count_emp1 return number is y number; begin select count(*) into y from emp1; return y; end; output: Function created.
--calling the function count_emp1()
declare c number:=0; begin c:=count_emp1(); dbms_output.put_line('count of employees is='||c); end;
output: Statement processed. count of employees is=8
--procedure to multiply 2 numbers
CREATE OR REPLACE PROCEDURE mul(a in number, b in number, c out number) is begin c:=a*b; end; --calling procedure mul() declare x number; y number; z number; begin x:=10; y:=50; mul(x,y,z); dbms_output.put_line('mul is'||z); end
--procedure for square of a number using In OUT
CREATE OR REPLACE PROCEDURE square(a in out number) is begin a:=a*a; end; --calling procedure square() declare a number; begin a:=9; square(a); dbms_output.put_line('square is'||a); end;