SELECT SUBSTR(REGEXP_SUBSTR('CCCCXXXCCCCCCCCCCCCCCCCXXCCCCCCCCCCCCCCCCCCCCCCC', '^(.)\1*.'), -2, 2) RESULT
FROM DUAL;
返回CX 这是另一个解决方案:
Select Replace (Wm_Concat (C), ',', '')
From
(Select Substr ('CCCXCCCXXXCCCCCCCCCCCCCCCCXXCCCCCCCCCCCCCCCC', Rownum, 1) C,
Min (Rownum) Rn
From Dual
Connect By Rownum <= Length ( 'CCCXCCCXXXCCCCCCCCCCCCCCCCXXCCCCCCCCCCCCCCCC')
Group By Substr ( 'CCCXCCCXXXCCCCCCCCCCCCCCCCXXCCCCCCCCCCCCCCCC', Rownum, 1)
Order By Rn
) X;
-- First, create a custom collection type (nested table type) to hold the unique characters:
CREATE OR REPLACE TYPE char_list AS TABLE OF VARCHAR2(1);
-- Next, create a pipelined function that splits the input string into unique characters and returns them as a collection:
CREATE OR REPLACE FUNCTION split_string(input_string VARCHAR2) RETURN char_list PIPELINED IS
BEGIN
FOR i IN 1..LENGTH(input_string) LOOP
PIPE ROW (SUBSTR(input_string, i, 1));
END LOOP;
RETURN;
END split_string;
/
-- Finally, use the pipelined function to list the unique characters in a string:
SELECT DISTINCT COLUMN_VALUE AS unique_character
FROM TABLE(split_string('YourInputStringToBeOrNotToBe'))
ORDER BY 1;
2条答案
按热度按时间41zrol4v1#
返回
CX
这是另一个解决方案:
它按出现的顺序返回所有唯一的字符。顺便说一句,是的,它看起来很可怕
xsuvu9jc2#
其他适合我的解决方案: