挑战能力的一个问题分析,敢不敢进来尝试一下?
请教各位大牛,有什么好的方法可以用java解析出下面sql中的表名,以及所用到的表的字段,格式如下:
表 字段
MID_PAYREF_FEE POLICYNO
....
MID_CMAINORIGIN WORKNUMBER
=======================================
还有嵌套的子查询别名,怎么解析呀?
java sql
SELECT
M.POLICYNO AS POLICYNO
,M.BUSINESSNO AS BUSINESSNO
,M.BUSINESSTYPE AS BUSINESSTYPE
,M.PAYTIMES AS PAYTIMES
,(SELECT K.CLASSCODE FROM CD_CLASS_RISK K WHERE K.RISKCODE = M.RISKCODE) AS CLASSCODE
,(SELECT K.CLASSCNAME FROM CD_CLASS_RISK K WHERE K.RISKCODE = M.RISKCODE) AS CLASSNAME
,M.RISKCODE AS RISKCODE
,(SELECT K.RISKCNAME FROM CD_RISK K WHERE K.RISKCODE = M.RISKCODE) AS RISKNAME
,M.BUSINESSNATURE AS BUSINESSNATURE
,(SELECT CB.CODECNAME FROM CD_BUSINESSNATURE CB WHERE CB.CODE = M.BUSINESSNATURE) AS BUSINESSNATURENAME
,M.CUSTOMERTYPE AS CUSTOMERTYPE
,(SELECT CA.CODECNAME FROM CD_CUSTOMERTYPE_ACC CA WHERE CA.CODE = M.CUSTOMERTYPE) AS CUSTOMERTYPENAME
,M.CHANNELCODE AS AGENTID
,(SELECT G.CHANNELCNAME FROM CD_AGENT G WHERE G.CHANNELCODE = M.CHANNELCODE) AS AGENTNAME
--,M.APPLIID AS APPLIID
,M.APPLINAME AS APPLINAME
-- ,M.INSUREDCODE AS INSUREDID
,M.INSUREDNAME AS INSUREDNAME
,M.OWNERID AS OWNERID
,(SELECT F.USERCNAME FROM ODS_USERINFO F WHERE F.USERCODE = M.OWNERID) AS OWNERNAME
,M.COMCODE AS COMCODE
,(SELECT Y.COMNAME FROM ODS_DCOMPANY Y WHERE Y.COMCODE = M.COMCODE) AS COMNAME
,M.BUSINESSFLAG AS BUSINESSFLAG
,M.ACCDATE AS ACCDATE
,M.FEETYPECODE AS FEETYPECODE
,M.SHOULDCURRENCY AS SHOULDCOMMCHARGECURRENCY
,-M.SHOULDVALUE AS SHOULDCOMMCHARGE
,-DECODE(M.SHOULDCURRENCY,'01',M.SHOULDVALUE) AS SHOULDCOMMCHARGECNY
,M.PAYREFDATE AS PAYREFDATE
,M.APPROVEDATE AS APPROVEDATE
,M.REALCURRENCY AS REALCOMMCHARGECURRENCY
,-M.REALVALUE AS REALCOMMCHARGE
,-M.REALSHOULDVALUE AS REALSHOULDCOMMCHARGE
,-DECODE(M.REALCURRENCY,'01',M.REALVALUE) AS REALCOMMCHARGECNY
--,PA.ACCVOUCHERNO AS ACCVOUCHERNO
--,PA.TSDATE AS EXPORTDATE
,R.SHOULDVALUE AS SIGNPREMIUM
,R.REALACCVALUE AS REALPREMIUM
,-NVL(M.SHOULDVALUE,0)+NVL(M.REALVALUE,0) AS SHOULDCOMMCHARGEBALANCE
,CASE WHEN R.R.SHOULDVALUE !=0 THEN -M.SHOULDVALUE/R.SHOULDVALUE ELSE 0 END AS SHOULDCOMMCHARGERATE
,CASE WHEN R.REALACCVALUE !=0 THEN -M.REALVALUE/R.REALACCVALUE ELSE 0 END AS REALCOMMCHARGERATE
,M.RECEIPTNO AS RECEIPTNO
,CASE WHEN M.BUSINESSTYPE='P' THEN W.PREMIUMCNY ELSE P.CHGPREMIUMCNY END AS PREMIUM
,SUBSTR(D.REGISTADDRESS,0,2) AS REGISTADDRESS
,W.WORKNUMBER AS WORKNUMBER
FROM MID_PAYREF_FEE M
--LEFT JOIN MID_PAYREF_ACCVOUCHERINFO PA ON M.RECEIPTNO = PA.RECEIPTNO AND PA.ACCITEMCODE IN('220201')
LEFT JOIN
(SELECT
B.POLICYNO AS POLICYNO,
CASE WHEN B.ENDORSENO IS NULL THEN B.POLICYNO ELSE B.ENDORSENO END AS BUSINESSNO,
SUM(B.SHOULDVALUE) AS SHOULDVALUE,
SUM(B.REALACCVALUE) AS REALACCVALUE
FROM ODS_PAYREF_POLICY B
GROUP BY B.POLICYNO, B.ENDORSENO
) R ON M.POLICYNO=R.POLICYNO AND M.BUSINESSNO=R.BUSINESSNO
LEFT JOIN MID_CMAINORIGIN W ON M.POLICYNO=W.POLICYNO
LEFT JOIN MID_PMAIN P ON M.BUSINESSNO=P.ENDORSENO
LEFT JOIN ODS_DCOMPANY D ON M.COMCODE=D.COMCODE
WHERE M.BUSINESSTYPE != 'C'
AND M.FEETYPECODE = 'FS'
AND (TRUNC(M.PAYREFDATE ,'DD') BETWEEN TO_DATE(SUBSTR('${RUNSTARTDATE}',1,10),'YYYY-MM-DD')
AND TO_DATE(SUBSTR('${RUNENDDATE}',1,10),'YYYY-MM-DD')
OR
TRUNC(M.APPROVEDATE ,'DD') BETWEEN TO_DATE(SUBSTR('${RUNSTARTDATE}',1,10),'YYYY-MM-DD')
AND TO_DATE(SUBSTR('${RUNENDDATE}',1,10),'YYYY-MM-DD')
OR
TRUNC(M.ACCDATE ,'DD') BETWEEN TO_DATE(SUBSTR('${RUNSTARTDATE}',1,10),'YYYY-MM-DD')
AND TO_DATE(SUBSTR('${RUNENDDATE}',1,10),'YYYY-MM-DD')
)