關於oracle中行轉列以及列轉行的記錄
阿新 • • 發佈:2019-02-16
SELECT X3.PK_COST_STANDARD,
X3.ORGID,
X3.ID,
X3.NAME,
X3.CONTROLLEDRANGE,
X3.CREATETIME,
X3.MODIFIER,
X3.MODIFIEDTIME,
WY_CONCAT(X3.STANDARDTYPE_NAME) AS STANDARDTYPE_NAME,
X3.FILE_ID AS STANDARDTYPE,
X3.REMIND,
X3.SUBSIDYTYPE,
X3.STANDARDFILE,
X3.DR,
X3.TS,
X3.CREATER,
X3.LEGALCODE,
A.ORGNAME AS ORGNAME,
P.ORGNAME AS CONTROLLEDRANGE_NAME,
M.STANDARDLIMIT AS STANDARDLIMIT,
M.STANDARDEXPLAIN AS STANARDEXPLAIN,
W.NAME AS REMIND_NAME,
C.EMPNAME AS CREATER_NAME,
D.EMPNAME AS MODIFIER_NAME
FROM (SELECT X.PK_COST_STANDARD,
X.ORGID,
X.ID,
X.NAME,
X.CONTROLLEDRANGE,
X.CREATETIME,
X.MODIFIER,
X.MODIFIEDTIME,
X2.COL_NAME AS STANDARDTYPE_NAME,
X.FILE_ID,
X.STANDARDTYPE,
X.REMIND,
X.SUBSIDYTYPE,
X.STANDARDFILE,
X.DR,
X.TS,
X.CREATER,
X.LEGALCODE
FROM (SELECT PK_COST_STANDARD,
ORGID,
ID,
NAME,
CONTROLLEDRANGE,
CREATETIME,
MODIFIER,
MODIFIEDTIME,
STANDARDTYPE AS FILE_ID,
REGEXP_SUBSTR(STANDARDTYPE, '[^,]+', 1, LEVEL) AS STANDARDTYPE,
REMIND,
SUBSIDYTYPE,
STANDARDFILE,
DR,
TS,
CREATER,
LEGALCODE
FROM (SELECT T.PK_COST_STANDARD,
T.ORGID,
T.ID,
T.NAME,
T.CONTROLLEDRANGE,
T.CREATETIME,
T.MODIFIER,
T.MODIFIEDTIME,
T.STANDARDTYPE,
T.REMIND,
T.SUBSIDYTYPE,
T.STANDARDFILE,
T.DR,
T.TS,
T.CREATER,
T.LEGALCODE
FROM RP_COST_STANDARD T)
CONNECT BY NOCYCLE
LEVEL <= REGEXP_COUNT(STANDARDTYPE, ',')+1
AND PK_COST_STANDARD = PRIOR PK_COST_STANDARD
AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL) X
LEFT JOIN PUB_COL_TABLE_RELATION X2
ON X2.ROWCODE IN X.STANDARDTYPE) X3
LEFT JOIN ORG_ORGANIZATION A
ON A.ORGID = X3.ORGID
LEFT JOIN ORG_EMPLOYEE C
ON C.EMPID = X3.CREATER
LEFT JOIN ORG_EMPLOYEE D
ON D.EMPID = X3.MODIFIER
LEFT JOIN RP_COST_STANDARD_CHILD M
ON M.PK_COST_STANDARD = X3.PK_COST_STANDARD
LEFT JOIN ORG_ORGANIZATION P
ON P.ORGID = X3.ORGID
LEFT JOIN PUB_DATA_DICTIONARY W
ON W.CODE = X3.REMIND
AND W.P_ID = '10146'
WHERE X3.DR = 0
AND M.DR = 0
AND X3.LEGALCODE = '000'
AND X3.ORGID IN (484)
GROUP BY X3.PK_COST_STANDARD,
X3.ORGID,
X3.ID,
X3.NAME,
X3.CONTROLLEDRANGE,
X3.CREATETIME,
X3.MODIFIER,
X3.MODIFIEDTIME,
A.ORGNAME,
P.ORGNAME,
X3.CONTROLLEDRANGE,
M.STANDARDLIMIT,
X3.SUBSIDYTYPE,
X3.STANDARDFILE,
M.STANDARDEXPLAIN,
W.NAME,
X3.REMIND,
C.EMPNAME,
D.EMPNAME,
X3.DR,
X3.TS,
X3.CREATER,
X3.LEGALCODE,
X3.FILE_ID
ORDER BY X3.CREATETIME DESC
X3.ORGID,
X3.ID,
X3.NAME,
X3.CONTROLLEDRANGE,
X3.CREATETIME,
X3.MODIFIER,
X3.MODIFIEDTIME,
WY_CONCAT(X3.STANDARDTYPE_NAME) AS STANDARDTYPE_NAME,
X3.FILE_ID AS STANDARDTYPE,
X3.REMIND,
X3.SUBSIDYTYPE,
X3.STANDARDFILE,
X3.DR,
X3.TS,
X3.CREATER,
X3.LEGALCODE,
A.ORGNAME AS ORGNAME,
P.ORGNAME AS CONTROLLEDRANGE_NAME,
M.STANDARDLIMIT AS STANDARDLIMIT,
M.STANDARDEXPLAIN AS STANARDEXPLAIN,
W.NAME AS REMIND_NAME,
C.EMPNAME AS CREATER_NAME,
D.EMPNAME AS MODIFIER_NAME
FROM (SELECT X.PK_COST_STANDARD,
X.ORGID,
X.ID,
X.NAME,
X.CONTROLLEDRANGE,
X.CREATETIME,
X.MODIFIER,
X.MODIFIEDTIME,
X2.COL_NAME AS STANDARDTYPE_NAME,
X.FILE_ID,
X.STANDARDTYPE,
X.REMIND,
X.SUBSIDYTYPE,
X.STANDARDFILE,
X.DR,
X.TS,
X.CREATER,
X.LEGALCODE
FROM (SELECT PK_COST_STANDARD,
ORGID,
ID,
NAME,
CONTROLLEDRANGE,
CREATETIME,
MODIFIER,
MODIFIEDTIME,
STANDARDTYPE AS FILE_ID,
REGEXP_SUBSTR(STANDARDTYPE, '[^,]+', 1, LEVEL) AS STANDARDTYPE,
REMIND,
SUBSIDYTYPE,
STANDARDFILE,
DR,
TS,
CREATER,
LEGALCODE
FROM (SELECT T.PK_COST_STANDARD,
T.ORGID,
T.ID,
T.NAME,
T.CONTROLLEDRANGE,
T.CREATETIME,
T.MODIFIER,
T.MODIFIEDTIME,
T.STANDARDTYPE,
T.REMIND,
T.SUBSIDYTYPE,
T.STANDARDFILE,
T.DR,
T.TS,
T.CREATER,
T.LEGALCODE
FROM RP_COST_STANDARD T)
CONNECT BY NOCYCLE
LEVEL <= REGEXP_COUNT(STANDARDTYPE, ',')+1
AND PK_COST_STANDARD = PRIOR PK_COST_STANDARD
AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL) X
LEFT JOIN PUB_COL_TABLE_RELATION X2
ON X2.ROWCODE IN X.STANDARDTYPE) X3
LEFT JOIN ORG_ORGANIZATION A
ON A.ORGID = X3.ORGID
LEFT JOIN ORG_EMPLOYEE C
ON C.EMPID = X3.CREATER
LEFT JOIN ORG_EMPLOYEE D
ON D.EMPID = X3.MODIFIER
LEFT JOIN RP_COST_STANDARD_CHILD M
ON M.PK_COST_STANDARD = X3.PK_COST_STANDARD
LEFT JOIN ORG_ORGANIZATION P
ON P.ORGID = X3.ORGID
LEFT JOIN PUB_DATA_DICTIONARY W
ON W.CODE = X3.REMIND
AND W.P_ID = '10146'
WHERE X3.DR = 0
AND M.DR = 0
AND X3.LEGALCODE = '000'
AND X3.ORGID IN (484)
GROUP BY X3.PK_COST_STANDARD,
X3.ORGID,
X3.ID,
X3.NAME,
X3.CONTROLLEDRANGE,
X3.CREATETIME,
X3.MODIFIER,
X3.MODIFIEDTIME,
A.ORGNAME,
P.ORGNAME,
X3.CONTROLLEDRANGE,
M.STANDARDLIMIT,
X3.SUBSIDYTYPE,
X3.STANDARDFILE,
M.STANDARDEXPLAIN,
W.NAME,
X3.REMIND,
C.EMPNAME,
D.EMPNAME,
X3.DR,
X3.TS,
X3.CREATER,
X3.LEGALCODE,
X3.FILE_ID
ORDER BY X3.CREATETIME DESC