我在结果列中有RAW数据,如下所示,分号分隔。
案例ID; HPMN; VPMN; IMSI;案例创建时间;案例报告时间;案件结案时间;最后通话时间;欺诈类型;报告备注; SDR值 - 创建(TAP); SDR值 - 已创建( NRT); SDR值 - 报告(TAP); SDR值 - 报告(NRT); SDR值 - 封闭(TAP); SDR值 - 封闭(NRT); SDR值 - 总(TAP); SDR值 - 总(NRT) ; SDR值 - 欺诈损失(TAP); SDR值 - 欺诈损失(NRT);案例状态ID;案例状态;分析员名称 - 已分配;分析员名称 - 关闭;组;旗帜; 7014472; NLXLT; ESPAT; 204046205787443; 17.05。 2018 00:00; 17.05.2018 05:57 ;; 18.05.2018 06:45:09;高使用率请求;; 10.35; 0; 10.35; 0; 0; 0; 20.72; 0; 10.37; 0; 512;待定; Gloriana; Lokesh; AllRoamingGroup P1;非托管; 7014473; OMNNT; ARETC; 422030204010256; 17.05.2018 00:01; 17.05.2018 05 :57 ;; 15.05.2018 19:47:09; OMNNT 10MB& 50 SDR ;; 51.35; 0; 51.35; 0; 0; 0; 51.35; 0; 0; 0; 512;待定; Gloriana; Jordan; AllRoamingGroup P1;非托管; 7014474; NLXLT; CZECM; 204046868687429; 17.05.2018 00:02 ;; 17.05.2018 00:24; 17.05.2018 15:36:23;呼叫第三国;; 0; 0; 0; 0; 0; 0; .44; 0; .44; 0; 2048;关闭不欺诈; Gloriana; Gloriana; AllRoamingGroup P1;非托管; 7014475; DOMCL; PRICL; 370021204427525; 17.05.2018 00:03 ;; 17.05.2018 00:26; 17.05.2018 22:44:19;呼叫第三国;; 0; 230.41; 0; 0; 0; 230.41; 1.94 ; 1200.07; 1.94; 969.66; 2048;关闭不欺诈; Gloriana; Gloriana; AllRoamingGroup P1;非托管;
但我需要以这种方式输出
我尝试了正则表达式,但无法获得所需的输出
答案 0 :(得分:1)
这将获得前16列....但您可以按照相同的模式添加额外的列:
Oracle 11g R2架构设置:
CREATE TABLE table_name ( value ) AS
SELECT 'Case ID;HPMN;VPMN;IMSI;Case Creation Time;Case Reporting Time;Case Closure Time;Last Call Time;Fraud Type;Reporting Remarks;SDR Value - Created (TAP);SDR Value - Created (NRT);SDR Value - Reported (TAP);SDR Value - Reported (NRT);SDR Value - Closed (TAP);SDR Value - Closed (NRT);SDR Value - Total (TAP);SDR Value - Total (NRT);SDR Value - Fraud Loss (TAP);SDR Value - Fraud Loss (NRT);Case Status ID;Case Status;Analyst Name - Assigned;Analyst Name - Closure;Group;Flag;7014472;NLXLT;ESPAT;204046205787443;17.05.2018 00:00;17.05.2018 05:57;;18.05.2018 06:45:09;High Usage Request ;;10.35;0; 10.35;0;0;0;20.72;0;10.37;0;512;Pending;Gloriana;Lokesh;AllRoamingGroup P1;non-hosted;7014473;OMNNT;ARETC;422030204010256;17.05.2018 00:01;17.05.2018 05:57;;15.05.2018 19:47:09;OMNNT 10MB & 50 SDRs;;51.35 ;0;51.35;0;0;0;51.35 ;0;0;0;512;Pending;Gloriana;Jordan;AllRoamingGroup P1;non-hosted;7014474;NLXLT;CZECM;204046868687429;17.05.2018 00:02;;17.05.2018 00:24;17.05.2018 15:36:23;Call third country;;0;0;0;0;0;0;.44;0;.44;0;2048;Closed Not Fraud;Gloriana;Gloriana;AllRoamingGroup P1;non-hosted; 7014475;DOMCL;PRICL;370021204427525;17.05.2018 00:03;;17.05.2018 00:26;17.05.2018 22:44:19;Call third country;;0;230.41;0;0;0;230.41;1.94;1200.07;1.94;969.66;2048;Closed Not Fraud;Gloriana;Gloriana;AllRoamingGroup P1;non-hosted;' FROM DUAL;
查询1 :
WITH data (
value,
lvl,
maxlvl,
Case_ID,
HPMN,
VPMN,
IMSI,
Case_Creation_Time,
Case_Reporting_Time,
Case_Closure_Time,
Last_Call_Time,
Fraud_Type,
Reporting_Remarks,
SDR_Value_Created_TAP,
SDR_Value_Created_NRT,
SDR_Value_Reported_TAP,
SDR_Value_Reported_NRT,
SDR_Value_Closed_TAP,
SDR_Value_Closed_NRT
) AS (
SELECT value,
1,
REGEXP_COUNT( value, '([^;]*);' ) / 26,
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 1, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 2, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 3, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 4, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 5, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 6, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 7, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 8, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 9, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 10, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 11, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 12, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 13, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 14, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 15, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, 0*26 + 16, NULL, 1 )
FROM table_name
UNION ALL
SELECT value,
lvl+1,
maxlvl,
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 1, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 2, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 3, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 4, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 5, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 6, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 7, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 8, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 9, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 10, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 11, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 12, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 13, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 14, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 15, NULL, 1 ),
REGEXP_SUBSTR( value, '([^;]*);', 1, lvl*26 + 16, NULL, 1 )
FROM data
WHERE lvl < maxlvl
)
SELECT Case_ID,
HPMN,
VPMN,
IMSI,
Case_Creation_Time,
Case_Reporting_Time,
Case_Closure_Time,
Last_Call_Time,
Fraud_Type,
Reporting_Remarks,
SDR_Value_Created_TAP,
SDR_Value_Created_NRT,
SDR_Value_Reported_TAP,
SDR_Value_Reported_NRT,
SDR_Value_Closed_TAP,
SDR_Value_Closed_NRT
FROM data
WHERE lvl > 1
<强> Results 强>:
| CASE_ID | HPMN | VPMN | IMSI | CASE_CREATION_TIME | CASE_REPORTING_TIME | CASE_CLOSURE_TIME | LAST_CALL_TIME | FRAUD_TYPE | REPORTING_REMARKS | SDR_VALUE_CREATED_TAP | SDR_VALUE_CREATED_NRT | SDR_VALUE_REPORTED_TAP | SDR_VALUE_REPORTED_NRT | SDR_VALUE_CLOSED_TAP | SDR_VALUE_CLOSED_NRT |
|----------|-------|-------|-----------------|--------------------|---------------------|-------------------|---------------------|----------------------|-------------------|-----------------------|-----------------------|------------------------|------------------------|----------------------|----------------------|
| 7014472 | NLXLT | ESPAT | 204046205787443 | 17.05.2018 00:00 | 17.05.2018 05:57 | (null) | 18.05.2018 06:45:09 | High Usage Request | (null) | 10.35 | 0 | 10.35 | 0 | 0 | 0 |
| 7014473 | OMNNT | ARETC | 422030204010256 | 17.05.2018 00:01 | 17.05.2018 05:57 | (null) | 15.05.2018 19:47:09 | OMNNT 10MB & 50 SDRs | (null) | 51.35 | 0 | 51.35 | 0 | 0 | 0 |
| 7014474 | NLXLT | CZECM | 204046868687429 | 17.05.2018 00:02 | (null) | 17.05.2018 00:24 | 17.05.2018 15:36:23 | Call third country | (null) | 0 | 0 | 0 | 0 | 0 | 0 |
| 7014475 | DOMCL | PRICL | 370021204427525 | 17.05.2018 00:03 | (null) | 17.05.2018 00:26 | 17.05.2018 22:44:19 | Call third country | (null) | 0 | 230.41 | 0 | 0 | 0 | 230.41 |
查询2 :
SELECT RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 1 ), ';' ) AS Case_ID,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 2 ), ';' ) AS HPMN,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 3 ), ';' ) AS VPMN,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 4 ), ';' ) AS IMSI,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 5 ), ';' ) AS Case_Creation_Time,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 6 ), ';' ) AS Case_Reporting_Time,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 7 ), ';' ) AS Case_Closure_Time,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 8 ), ';' ) AS Last_Call_Time,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 9 ), ';' ) AS Fraud_Type,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 10 ), ';' ) AS Reporting_Remarks,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 11 ), ';' ) AS SDR_Value_Created_TAP,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 12 ), ';' ) AS SDR_Value_Created_NRT,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 13 ), ';' ) AS SDR_Value_Reported_TAP,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 14 ), ';' ) AS SDR_Value_Reported_NRT,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 15 ), ';' ) AS SDR_Value_Closed_TAP,
RTRIM( REGEXP_SUBSTR( value, '.*?;', 1, l.COLUMN_VALUE*26 + 16 ), ';' ) AS SDR_Value_Closed_NRT
FROM table_name t
CROSS JOIN
TABLE(
CAST(
MULTISET(
SELECT LEVEL
FROM DUAL
CONNECT BY REGEXP_SUBSTR( t.value, '.*?;', 1, LEVEL*26 + 1 ) IS NOT NULL
)
AS SYS.ODCINUMBERLIST
)
) l
<强> Results 强>:
| CASE_ID | HPMN | VPMN | IMSI | CASE_CREATION_TIME | CASE_REPORTING_TIME | CASE_CLOSURE_TIME | LAST_CALL_TIME | FRAUD_TYPE | REPORTING_REMARKS | SDR_VALUE_CREATED_TAP | SDR_VALUE_CREATED_NRT | SDR_VALUE_REPORTED_TAP | SDR_VALUE_REPORTED_NRT | SDR_VALUE_CLOSED_TAP | SDR_VALUE_CLOSED_NRT |
|----------|-------|-------|-----------------|--------------------|---------------------|-------------------|---------------------|----------------------|-------------------|-----------------------|-----------------------|------------------------|------------------------|----------------------|----------------------|
| 7014472 | NLXLT | ESPAT | 204046205787443 | 17.05.2018 00:00 | 17.05.2018 05:57 | (null) | 18.05.2018 06:45:09 | High Usage Request | (null) | 10.35 | 0 | 10.35 | 0 | 0 | 0 |
| 7014473 | OMNNT | ARETC | 422030204010256 | 17.05.2018 00:01 | 17.05.2018 05:57 | (null) | 15.05.2018 19:47:09 | OMNNT 10MB & 50 SDRs | (null) | 51.35 | 0 | 51.35 | 0 | 0 | 0 |
| 7014474 | NLXLT | CZECM | 204046868687429 | 17.05.2018 00:02 | (null) | 17.05.2018 00:24 | 17.05.2018 15:36:23 | Call third country | (null) | 0 | 0 | 0 | 0 | 0 | 0 |
| 7014475 | DOMCL | PRICL | 370021204427525 | 17.05.2018 00:03 | (null) | 17.05.2018 00:26 | 17.05.2018 22:44:19 | Call third country | (null) | 0 | 230.41 | 0 | 0 | 0 | 230.41 |