我的数据如下所示。
ColumnA
APX-0150004-225 02A,APX-0150004-234 02A
APX-0170009-001 04C,APX-0170021-002 04C,APX-0170021-004 02R
APX-0170012-001 04C,APX-0170012-002 02R,APX-0170021-003 04C,APX-0170021-005 01R
我想在逗号前用替换每三个字符,输出应如下所示
ColumnA
APX-0150004-225 ,APX-0150004-234
APX-0170009-001 ,APX-0170021-002 ,APX-0170021-004
APX-0170012-001 ,APX-0170012-002 ,APX-0170021-003 ,APX-0170021-005
答案 0 :(得分:0)
Oracle安装程序:
CREATE TABLE table_name ( ColumnA ) AS
SELECT 'APX-0150004-225 02A,APX-0150004-234 02A' FROM DUAL UNION ALL
SELECT 'APX-0170009-001 04C,APX-0170021-002 04C,APX-0170021-004 02R' FROM DUAL UNION ALL
SELECT 'APX-0170012-001 04C,APX-0170012-002 02R,APX-0170021-003 04C,APX-0170021-005 01R' FROM DUAL;
<强>查询强>:
SELECT REGEXP_REPLACE( ColumnA, '[^,]{3}(,|$)', '\1' ) AS ColumnA
FROM table_name
<强>输出强>:
COLUMNA
------------------------------------------------------------------
APX-0150004-225 ,APX-0150004-234
APX-0170009-001 ,APX-0170021-002 ,APX-0170021-004
APX-0170012-001 ,APX-0170012-002 ,APX-0170021-003 ,APX-0170021-005