oralce 将一个字符串里的数据按逗号分隔去重再拼接成一个新的字符串

sql结果集某列值显示如下:

'00010430, 00228290, 07046884,07046884, 07383953'

 希望显示的结果

'00010430, 00228290,07046884, 07383953'

 

新建一个function 实现此功能

create or replace
FUNCTION        "SF_SPLIT_ACCOUNT_ID_LIST" (
    account_id_list IN VARCHAR2
)RETURN VARCHAR2 AS
v_account_id_list VARCHAR2(5000);

BEGIN

WITH ACCTS AS (
SELECT DISTINCT str from (
SELECT REGEXP_SUBSTR(replace(account_id_list,', ',','), '[^,]+', 1, LEVEL, 'i') AS STR  
  FROM DUAL  
CONNECT BY LEVEL <=  
           LENGTH(replace(account_id_list,', ',',')) 
           - LENGTH(REGEXP_REPLACE(replace(account_id_list,', ',','), ',', ''))+1))
SELECT wm_concat(STR) INTO v_account_id_list FROM ACCTS;

RETURN v_account_id_list;

END SF_SPLIT_ACCOUNT_ID_LIST; 

 

你可能感兴趣的:(oracle)