Procedure to Reverse a String
The following tip uses a procedure that reverses a string provided as an argument.
SQL> create or replace procedure rev(x in varchar2) as
2 c char(1);
3 i number;
4 begin
5 for i in 1..length(x) loop
6 select substr(x,length(x)-i+1,1) into c from dual;
7 dbms_output.put(c);
8 end loop;
9 dbms_output.put_line(' ');
10 end;
11 /
Procedure created.
SQL> set serverout on
SQL> exec rev('Java')
avaJ
PL/SQL procedure successfully completed.
SQL> exec rev('Oracle')
elcarO
PL/SQL procedure successfully completed.
No comments:
Post a Comment