方法一
select a.*,
REGEXP_SUBSTR(a.rolecode,'[^,]+',1,l) AS rolecode from p_user a,(SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=100) b WHERE l <=LENGTH(a.rolecode) - LENGTH(REPLACE(rolecode,','))+1 使用函数REGEXP_SUBSTR拆分字符串: 5个参数 第一个是输入的字符串 第二个是正则表达式 第三个是标识从第几个字符开始正则表达式匹配。(默认为1) 第四个是标识第几个匹配组。(默认为1) 第五个是是取值范围: i:大小写不敏感; c:大小写敏感; n:点号 . 不匹配换行符号; m:多行模式; x:扩展模式,忽略正则表达式中的空白字符。 SELECT a.*,REGEXP_SUBSTR(servicereqid,'[^;]+',l) AS servicereq FROM sum_portal_satisfaction a,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">WHERE l <=LENGTH(servicereqid) - LENGTH(REPLACE(servicereqid,';'))+1 ORDER BY 1,2; ----SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=100; 生成1到100的数据行。 ----l <=LENGTH(servicereqid) - LENGTH(REPLACE(servicereqid,';'))+1,注意此处是‘L’并非‘1’,上面的REGEXP_SUBSTR的第四个参数也一样。 ---下面为拆分字符串,再进行的行转列 create or replace view v_sum_portal_satisfaction_sr as select survey_type,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">survey_time,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">center_code,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">center_name,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">city_id,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">city_name,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">REGEXP_SUBSTR(servicereqid,l) AS servicereqid,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">REGEXP_SUBSTR(servicereqname,l) AS servicereqname,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">sum(decode(survey_value,sur_times,null)) giveup_times,--调查值 -1:未处理 0:用户放弃 1:很满意 2.满意 3.对csr不满意 4.对其它不满意 sum(sur_times) sur_times group by subslevelid,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">servicereqid,51);font-family:Simsun;font-size:14px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;list-style-image:none;list-style-position:outside;list-style-type:none;margin-left:0px;text-align:left;text-decoration:none;text-indent:28px;text-transform:none;word-spacing:0px;">servicereqname,l
方法二: