SELECT * FROM ( SELECT a.POLICY_NO AS businessNo, a.ENDORSE_SEQ_NO AS businessSerialNo, a.TOTAL_SERIAL_NO AS totalSerialNo, a.BILL_TYPE AS billType, a.ISSUE_COMPANY AS companyCode, a.PLAN_CCY AS currency, a.EXCHANGE_RATE AS exchangeRate, a.PLAN_FEE AS totalAmount, a.VAT AS taxAmount, a.BUSINESS_NO AS proposalNo, CONVERT(decimal(16, 2), round(a.PLAN_FEE * a.EXCHANGE_RATE, 2)) AS exchangeTotalAmount, CONVERT(decimal(16, 2), round(a.VAT * a.EXCHANGE_RATE, 2)) AS exchangeTaxAmount, 'P' AS certiType, (CASE a.VAT WHEN '0' THEN 'N' ELSE 'Y' END) AS taxExemptFlag, a.PAY_NO AS payNo, ( SELECT top 1 g.LOSS_NO FROM GPLOSSFEE g WHERE g.POLICY_NO = a.POLICY_NO) AS lossNo FROM GPPOLICYPLAN a LEFT JOIN ( SELECT t.POLICY_NO, t.BUSINESS_SEQNO, t.PAY_NO, t.FEE_TYPE_CODE, t.TOTAL_SERIAL_NO FROM GPINPUTVATINVOICEREL t, GPPOLICYPLAN b WHERE t.BUSINESS_NO = b.POLICY_NO AND t.BUSINESS_SEQNO = b.ENDORSE_SEQ_NO AND t.PAY_NO = b.PAY_NO AND t.FEE_TYPE_CODE = b.BILL_TYPE AND t.TOTAL_SERIAL_NO = b.TOTAL_SERIAL_NO) p ON a.POLICY_NO = p.POLICY_NO AND a.ENDORSE_SEQ_NO = p.BUSINESS_SEQNO AND a.PAY_NO = p.PAY_NO AND a.BILL_TYPE = p.FEE_TYPE_CODE AND a.TOTAL_SERIAL_NO = p.TOTAL_SERIAL_NO WHERE (a.PAY_NO != p.PAY_NO OR p.PAY_NO IS NULL) AND a.PLAN_FEE < 0 AND a.BILL_TYPE != 'R10' AND a.COMPANY_CODE IN ( '729021' , '729020' , '729023' , '729022' , '729000' , '729061' , '729060' , '729041' , '729040' , '729081' , '729080' , '729079' , '729010' , '729031' , '729078' , '729077' , '729011' , '729050' , '729072' , '729071' , '729074' , '729052' , '729030' , '729051' , '729073' , '729070' , '86' ) ) WHERE rownum <= 5 oracl怎么改写
时间: 2023-11-22 12:05:27 浏览: 85
Unofficial-Quake-3-Map-Specs.rar_quake
这个SQL查询语句可以改写为以下形式:
```
SELECT *
FROM (
SELECT a.POLICY_NO AS businessNo,
a.ENDORSE_SEQ_NO AS businessSerialNo,
a.TOTAL_SERIAL_NO AS totalSerialNo,
a.BILL_TYPE AS billType,
a.ISSUE_COMPANY AS companyCode,
a.PLAN_CCY AS currency,
a.EXCHANGE_RATE AS exchangeRate,
a.PLAN_FEE AS totalAmount,
a.VAT AS taxAmount,
a.BUSINESS_NO AS proposalNo,
CAST(ROUND(a.PLAN_FEE * a.EXCHANGE_RATE, 2) AS DECIMAL(16, 2)) AS exchangeTotalAmount,
CAST(ROUND(a.VAT * a.EXCHANGE_RATE, 2) AS DECIMAL(16, 2)) AS exchangeTaxAmount,
'P' AS certiType,
CASE a.VAT
WHEN '0' THEN 'N'
ELSE 'Y'
END AS taxExemptFlag,
a.PAY_NO AS payNo,
(
SELECT TOP 1 g.LOSS_NO
FROM GPLOSSFEE g
WHERE g.POLICY_NO = a.POLICY_NO
) AS lossNo
FROM GPPOLICYPLAN a
LEFT JOIN (
SELECT t.POLICY_NO,
t.BUSINESS_SEQNO,
t.PAY_NO,
t.FEE_TYPE_CODE,
t.TOTAL_SERIAL_NO
FROM GPINPUTVATINVOICEREL t
INNER JOIN GPPOLICYPLAN b ON t.BUSINESS_NO = b.POLICY_NO
AND t.BUSINESS_SEQNO = b.ENDORSE_SEQ_NO
AND t.PAY_NO = b.PAY_NO
AND t.FEE_TYPE_CODE = b.BILL_TYPE
AND t.TOTAL_SERIAL_NO = b.TOTAL_SERIAL_NO
) p ON a.POLICY_NO = p.POLICY_NO
AND a.ENDORSE_SEQ_NO = p.BUSINESS_SEQNO
AND a.PAY_NO = p.PAY_NO
AND a.BILL_TYPE = p.FEE_TYPE_CODE
AND a.TOTAL_SERIAL_NO = p.TOTAL_SERIAL_NO
WHERE (a.PAY_NO != p.PAY_NO OR p.PAY_NO IS NULL)
AND a.PLAN_FEE < 0
AND a.BILL_TYPE != 'R10'
AND a.COMPANY_CODE IN ('729021', '729020', '729023', '729022', '729000', '729061', '729060', '729041', '729040', '729081', '729080', '729079', '729010', '729031', '729078', '729077', '729011', '729050', '729072', '729071', '729074', '729052', '729030', '729051', '729073', '729070', '86')
ORDER BY ROWNUM
)
WHERE ROWNUM <= 5
```
主要的改动包括:
- 将转换数据类型的函数 CONVERT 改写为 CAST。
- 将子查询的 TOP 1 改成了 Oracle 中的 ROWNUM。
- 将 LEFT JOIN 改为 INNER JOIN,并将 JOIN 条件移到了 ON 子句中。
阅读全文