1. During the development process, the problem of "column to row\row to column" is often encountered, as shown in the figure below
2. Column to row
2.1 现场数据库一般会有中文逗号,分号、、、、、等情况。转之前我们先进行替换
select
(SELECT REGEXP_REPLACE(m.ALTBE,'[;||;||,||、]', ',') AS NAMES FROM DUAL)
from REG_AltAccItem m WHERE id = '141000013302990181'
2.2 列转行
SELECT REGEXP_SUBSTR('100000003,100000007,100000018,100000020,100000021,100000022,100000023,410000002,410000003,','[^,]+', 1, ROWNUM) AS code FROM DUAL
CONNECT BY ROWNUM <= LENGTH(REGEXP_REPLACE('100000003,100000007,100000018,100000020,100000021,100000022,100000023,410000002,410000003,', '[^,]+', NULL)) + 1
3. Row to column
Parameter Explanation
String: The string that needs regular processing.
pattern: regular expression.
position: starting position (regularized from the first number of the string, the default is 1, note: the starting position of the string in the database is 1).
Occurrence: Get the number of groups separated by regular expressions.
modifier: mode ('i' is case-insensitive, 'c' is case-sensitive. There is no 'c' by default).
SELECT wm_concat(NAME) FROM (
select NAME from CODE_REGALLLICCODE a INNER JOIN (
SELECT REGEXP_SUBSTR('100000003,100000007,100000018,100000020,100000021,100000022,100000023,410000002,410000003,','[^,]+', 1, ROWNUM) AS code FROM DUAL
CONNECT BY ROWNUM <= LENGTH(REGEXP_REPLACE('100000003,100000007,100000018,100000020,100000021,100000022,100000023,410000002,410000003,', '[^,]+', NULL)) + 1) b ON a.CODE = b.code
)