Practical 7

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Practical 7 : FUNCTIONS IN PL/SQL

7a) Create a function to display square of a number

create or replace function func1

return int

as

A int :=24;

begin

return A*A;

end;

Run cmd
Function created.

Select func1 from dual

Output

FUNC1

576

7b) Create a function to swap two numbers

create or replace function func2

return varchar

as

a int:=24;

b int:=32;

c int;

begin

a:=a;

c:=a;

a:=b;

b:=c;
return('a is now:'||a||''||'and b is now:'||b);

end;

Run Cmd
Function created.

Select func2 from dual

Output

a is now:32and b is now:24

7c) Create a function to display the greatest among two numbers

create or replace function func3

return varchar

as

a int:=12;

b int:=24;

begin

if(a>b)then

return (a||'is greater than'||b);

else

return (b||'is greater than'||a);

end if

end;

Run Cmd
Function created.

Select func3 from dual

Output :
FUNC3

24is greater than12

7d) Create a function to print the reverse of a string

create function rev

return varchar

as

str varchar(30):= 'FYIT GOOD STUDENT';

len int;

str1 varchar(30);

begin

len:=length(str);

for I in reverse 1..len loop

str1:=str1|| substr(str,I,1);

end loop;

return('reverse of the string is: '||str1);

end;

Run Cmd
Function created.

Select rev from dual;

Output

REV3

reverse of the string is: TNEDUTS DOOG TIYF

You might also like