KEMBAR78
Functions | PDF
0% found this document useful (0 votes)
4 views3 pages

Functions

The document contains PL/SQL code defining several functions: 'findMax' to return the maximum of two numbers, 'emptot' to count the number of records in the 'emp' table, and 'reverse_it' to reverse an integer. It also includes examples of how to use these functions, such as finding the maximum of 23 and 45, counting employees, and reversing the number 4321. The code demonstrates basic PL/SQL operations including variable declaration, conditional statements, and loops.

Uploaded by

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

Functions

The document contains PL/SQL code defining several functions: 'findMax' to return the maximum of two numbers, 'emptot' to count the number of records in the 'emp' table, and 'reverse_it' to reverse an integer. It also includes examples of how to use these functions, such as finding the maximum of 23 and 45, counting employees, and reversing the number 4321. The code demonstrates basic PL/SQL operations including variable declaration, conditional statements, and loops.

Uploaded by

shiva
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

create or replace FUNCTION findMax(x IN number, y IN number)

RETURN number

IS

z number;

BEGIN

IF x > y THEN

z:= x;

ELSE

Z:= y;

END IF;

RETURN z;

END;

DECLARE

a number;

b number;

c number;

BEGIN

a:= 23;

b:= 45;

c := findMax(a, b);

dbms_output.put_line(' Maximum of (23,45): ' || c);

END;

/
CREATE OR REPLACE FUNCTION emptot

RETURN number IS

total number(2) := 0;

BEGIN

SELECT count(*) into total

FROM emp;

RETURN total;

END;

select emptot from dual;

set serveroutput on;

create or replace function reverse_it( x IN int)

return int

as

z int;

c int;

n int;

rev int:=0;

r int;

begin

n := x;

while (n > 0)

loop

r := mod(n, 10);
rev := (rev * 10) + r;

n := trunc(n / 10);

end loop;

z := rev;

return z;

end ;

declare

a int:=4321;

c number;

BEGIN

c := reverse_it(a);

dbms_output.put_line('the reverse of number is ' || c);

END;

You might also like