Home » Developer & Programmer » Forms » How to reverse a string / array (merged)
How to reverse a string / array (merged) [message #254997] Mon, 30 July 2007 06:40 Go to next message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
how to use array or string? and how to reverse a string
Re: reverse an array [message #254999 is a reply to message #254997] Mon, 30 July 2007 06:44 Go to previous messageGo to next message
ammishra
Messages: 179
Registered: January 2007
Location: india
Senior Member
try this one ..

select reverse('ganesh') from dual



--Yash
on forms [message #255002 is a reply to message #254999] Mon, 30 July 2007 06:51 Go to previous messageGo to next message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
ya it works in sql but not on forms? suggest what to do on forms
Re: on forms [message #255003 is a reply to message #255002] Mon, 30 July 2007 06:52 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Well, maybe you should have asked this in the Forms Forum??
just a hint [message #255017 is a reply to message #254997] Mon, 30 July 2007 07:35 Go to previous messageGo to next message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
plz ppl at least give a hint
Re: reverse a string/array [message #255021 is a reply to message #254997] Mon, 30 July 2007 07:39 Go to previous messageGo to next message
azamkhan
Messages: 557
Registered: August 2005
Senior Member
I think its very simple.... to reverse a string you can use INSTR and SUBSTR functions with loop.

To reverse an array. You can use another array to assigned the reverse values from the 1st array. Two arrays will be easy than doing it in one array.
string reverse [message #255029 is a reply to message #255021] Mon, 30 July 2007 08:01 Go to previous messageGo to next message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
yar please write it if its that easy.
thanxs
Re: string reverse [message #255103 is a reply to message #255029] Mon, 30 July 2007 11:21 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
A reverse function is trivial:
SQL> CREATE OR REPLACE FUNCTION fun_reverse (par_str IN CHAR)
  2  RETURN CHAR
  3  IS
  4    retval VARCHAR2(100);
  5  BEGIN
  6    FOR i IN REVERSE 1 .. LENGTH(par_str) LOOP
  7      retval := retval || SUBSTR(par_str, i, 1);
  8    END LOOP;
  9
 10    RETURN (retval);
 11  END;
 12  /

Function created.

SQL>
SQL> SELECT fun_reverse ('A quick brown fox jumps over a lazy dog.') result
  2    FROM dual
  3  UNION ALL
  4  SELECT REVERSE('A quick brown fox jumps over a lazy dog.')
  5    FROM dual;

RESULT
---------------------------------------------------------------
.god yzal a revo spmuj xof nworb kciuq A
.god yzal a revo spmuj xof nworb kciuq A

SQL>


I didn't get the point in your first question (how to use strings and arrays); what exactly would you like to ask here?
Re: string reverse [message #255229 is a reply to message #255103] Tue, 31 July 2007 01:24 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Reverse is the one of the very few undocumented functions in SQL.

MHE
Re: string reverse [message #255460 is a reply to message #255229] Wed, 01 August 2007 00:07 Go to previous messageGo to next message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
if u want to reverse an array
its quite simple
---------------
create two objects of table by char or int,
------------
and copy the contents of one array into other using by index, in a loop;
index must be reverse.
please senior members never give the solutions of such questions , hints are good to goom an individual as
michel sayssss
Re: string reverse [message #256057 is a reply to message #255229] Thu, 02 August 2007 20:55 Go to previous message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
I thought 'reverse' was only for 'loop' usage only.
From Oracle PL/SQl documentation on FOR-LOOP
By default, iteration proceeds upward from the lower bound to the higher bound. However, if you use the keyword REVERSE, iteration proceeds downward from the higher bound to the lower bound, as the example below shows. After each iteration, the loop counter is decremented.
FOR i IN REVERSE 1..3 LOOP  -- assign the values 3,2,1 to i
   sequence_of_statements;  -- executes three times
END LOOP;


David
Previous Topic: HOW TO SAVE DATA GENERATED SO I CAN KEEP RE-USING THE SAME DATA TO BE ABLE TO SAVE IT TO FILE
Next Topic: to diplay on form
Goto Forum:
  


Current Time: Sun Feb 09 18:46:28 CST 2025