我的查询在Vet_Ben_Code列中带有空值和数字。 我希望所有NULL读取为0,所有其他数字保持不变,我该怎么做。这是查询:
SELECT STU.Term_Code,
STU.PIDM,
STU.Vet,
RXR.Vet_Ben_Code
FROM
(SELECT CST.Term_Code,
CST.PIDM,
SPB.Vet
FROM
(SELECT Term_Code,
PIDM
FROM CHELINK.Combined_Student_Table
WHERE Term_Code BETWEEN '201170' AND '201670'
)CST
INNER JOIN
(SELECT SPBPERS_PIDM,
SPBPERS_VETC_FILE_NUMBER Vet
FROM SATURN.SPBPERS
WHERE SPBPERS_VETC_FILE_NUMBER LIKE 'Y%'
OR SPBPERS_VETC_FILE_NUMBER LIKE 'y%'
)SPB
ON CST.PIDM = SPB.SPBPERS_PIDM
)STU
LEFT JOIN
(SELECT RXRVETN_Term_Code_VA AS Term_Code,
RXRVETN_PIDM AS PIDM,
RXRVETN_Vetc_Code AS Vet_Ben_Code
FROM FAISMGR.RXRVETN
WHERE RXRVETN_Term_Code_VA BETWEEN '201170' AND '201670'
)RXR
ON STU.Term_Code = RXR.Term_Code
AND STU. PIDM = RXR.PIDM
答案 0 :(得分:2)
您可以使用NVL()
或COALESCE()
。
SELECT NVL(NULL, 0) from dual;
SELECT COALESCE(NULL, 0) from dual;
NVL
将返回非null值,如果为null,则返回第二个参数。
COALESCE
允许多个参数,并将评估参数列表中的第一个非空值。
答案 1 :(得分:1)
如果Oracle然后使用它: 从dual;
中选择NVL(NULL,0)如果SQL使用此: 从双重中选择ISNULL(STU.Term_Code,0);
答案 2 :(得分:0)