PL/SQL function
Find the second max salary from employee
========================================================
create function second_max1
return number
is
b number(10);
begin
select max(salary) into b from employee where salary!=(select max(salary) from employee);
return b;
end;
/
declare
b number(10);
begin
b:=second_max1;
dbms_output.put_line(b);
end;
/
========================================================
create function second_max1
return number
is
b number(10);
begin
select max(salary) into b from employee where salary!=(select max(salary) from employee);
return b;
end;
/
declare
b number(10);
begin
b:=second_max1;
dbms_output.put_line(b);
end;
/
Find the number of words in a Sentence
===============================================
--the function body
create or replace function wordcount(n in varchar2)
return number
as
l number;
i number;
begin
l:=1;
for i in 1..length(n)
loop
if(substr(n,i,1)=' ')
then
l:=l+1;
end if;
end loop;
return l;
end;
/
--calling the function
declare
n varchar2(20);
c number;
begin
n:='&n';
c:=wordcount(n);
dbms_output.put_line(c);
end;
/
===============================================
--the function body
create or replace function wordcount(n in varchar2)
return number
as
l number;
i number;
begin
l:=1;
for i in 1..length(n)
loop
if(substr(n,i,1)=' ')
then
l:=l+1;
end if;
end loop;
return l;
end;
/
--calling the function
declare
n varchar2(20);
c number;
begin
n:='&n';
c:=wordcount(n);
dbms_output.put_line(c);
end;
/
Comments
Post a Comment