Home » SQL & PL/SQL » SQL & PL/SQL » reverse nvarchar
reverse nvarchar [message #181269] Fri, 07 July 2006 17:22 Go to next message
stacdab
Messages: 4
Registered: July 2006
Junior Member
Hello all.

Does anyone how to get around this problem? We need to reverse nvarchar strings.

SQL> select reverse('abcdefg'), reverse(n'abcdefg') from dual;

REVERSE REVERSE
------- -------
gfedcba ┐┐┐┐┐┐┐



Thanks.

Re: reverse nvarchar [message #181286 is a reply to message #181269] Sat, 08 July 2006 04:04 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Ouch, of all the Oracle functions you choose the one that is not documented. What happens if you write your own 'nvarchar reverse'?
CREATE OR REPLACE FUNCTION n_reverse(p_str IN NVARCHAR2)
RETURN NVARCHAR2
AS
  v_return NVARCHAR2(4000);
BEGIN
  FOR i in 1..length(p_str)
  LOOP
    v_return := SUBSTR(p_str,i,1)||v_return;
  END LOOP;

  RETURN v_return;
END n_reverse;


You can add the DETERMINISTIC keyword (you don't access any database objects) but I don't think you'd see any performance increase.

A second option:
select reverse('abcdefg'), reverse(to_char(n'abcdefg')) from dual;


Like I said: REVERSE is the one Oracle SQL function that is not documented but apparently NVARCHAR is not supported.

MHE
Re: reverse nvarchar [message #181304 is a reply to message #181286] Sat, 08 July 2006 06:46 Go to previous message
stacdab
Messages: 4
Registered: July 2006
Junior Member
Thanks for the help. I guess we'll have to roll our own.
Previous Topic: Problem return value in Function
Next Topic: Non-Unique Index
Goto Forum:
  


Current Time: Tue Jul 22 23:25:33 CDT 2025