0% found this document useful (0 votes)
4 views1 page

SQL Procedures for Reversing Numbers and Strings

Uploaded by

solive
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

SQL Procedures for Reversing Numbers and Strings

Uploaded by

solive
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

--REVERSE NUMBER

declare
sn [Link]%type:=&ssn;
rev number:=0;
begin
select ssn into sn from employee where ssn=sn;
while sn>0 loop
rev:=(rev*10)+mod(sn,10);
sn:=trunc(sn/10);
end loop;
dbms_output.put_line('Reversed value is: '||rev);
end;

--REVERSE STRING
--using reverse method
declare
fname varchar2(10):='&fname';
rev varchar2(10);
begin
select reverse(fname) into rev from dual; --rev:=reverse(fname);
dbms_output.put_line('rev name ' ||rev);
end;
--using while loop
declare
fname varchar2(10):='&fname';
rev varchar2(10);
i number;
begin
i:=length(fname);
while(i>0) loop
rev:=rev|| substr(fname,i,1);
i:=i-1;
end loop;
dbms_output.put_line('rev name ' ||rev);
end;
--using for loop
declare
fname varchar2(10):='&fname';
rev varchar2(10);
i number;
begin
i:=length(fname);
for o in reverse 1..i loop --for o in 1..i loop
rev:=rev|| substr(fname,o,1); --rev:=rev||substr(fname,i-o+1,1);
end loop;
dbms_output.put_line('rev name ' ||rev);
end;

--GET ALL NAMES FROM EMPLOYEE


declare
begin
for d in (select fname from employee) loop
dbms_output.put_line([Link]);
end loop;
end;

You might also like