About me:Oracle ACE pro,optimistic,passionate and harmonious. Focus on ORACLE,MySQL and other database programming,peformance tuning,db design, j2ee,Linux/AIX,Architecture tech,etc
全部博文(173)
分类: Oracle
2013-11-26 20:31:06
SELECT REVERSE('测试reverse') FROM dual; --注意中文可能乱码 SELECT REVERSE('测试reverse') FROM dual; --2次reverse正常 SELECT reverse(REVERSE('测试reverse')) FROM dual; |
SELECT utl_raw.cast_to_varchar2(utl_raw.reverse(utl_raw.cast_to_raw('测试reverse'))) FROM dual; --中文同上 |
WITH t AS (SELECT '测试reverse' AS str FROM dual) SELECT REPLACE(sys_connect_by_path(res_str, '|'), '|') AS reversed_string FROM (SELECT length(str) - rownum AS rn, substr(str, rownum, 1) res_str FROM t CONNECT BY rownum <= length(str)) WHERE connect_by_isleaf = 1 CONNECT BY rn = PRIOR rn + 1 START WITH rn = 0; --11g r2递归with WITH t (str, s, c) AS ( SELECT '测试reverse' str, CAST(NULL AS VARCHAR2(15)) s, 0 FROM dual UNION ALL SELECT str, s || substr(str, -c - 1, 1), c + 1 FROM t WHERE c <= length(str) ) SELECT MAX(str) str, MAX(s) rev_str FROM t; |
SELECT REPLACE(WM_CONCAT(NAME), ',', '') REV_NAME FROM (SELECT LEVEL, SUBSTR('测试reverse', LEVEL, 1) NAME FROM DUAL CONNECT BY LEVEL <= LENGTH('测试reverse') ORDER BY 1 DESC); SELECT listagg(str) within GROUP( ORDER BY ord) FROM (SELECT rownum ord, substr('测试reverse', LEVEL * -1, 1) str FROM dual CONNECT BY LEVEL <= length('测试reverse')); |