2013-05-28 57 views
0

我有以下查詢:NVL函數在子查詢

select E.EQUIPMENT_GID, NVL((SELECT SUBSTR(ES.STATUS_VALUE_GID,INSTR(ES.STATUS_VALUE_GID, '.')+1) FROM EQUIPMENT_STATUS ES WHERE ES.EQUIPMENT_GID=E.EQUIPMENT_GID 
AND ES.STATUS_TYPE_GID LIKE '%EQUIPMENT_STATUS' AND ROWNUM=1),'ZZZ') AS E_STATUS, NVL((SELECT EREF.EQUIPMENT_REFNUM_QUAL_GID FROM EQUIPMENT_REFNUM EREF WHERE EREF.EQUIPMENT_GID = E.EQUIPMENT_GID 
AND EREF.EQUIPMENT_REFNUM_QUAL_GID LIKE '%PERMANENT DISTRICT%' and rownum=1),'ZZZ') AS PERM_DISTRICT_REF, 'PSKL-'||REPLACE(SUBSTR((SELECT EREF.EQUIPMENT_REFNUM_QUAL_GID FROM EQUIPMENT_REFNUM EREF 
WHERE EREF.EQUIPMENT_GID = E.EQUIPMENT_GID AND EREF.EQUIPMENT_REFNUM_QUAL_GID LIKE '%PERMANENT DISTRICT%' AND ROWNUM=1),(INSTR((SELECT EREF.EQUIPMENT_REFNUM_QUAL_GID FROM EQUIPMENT_REFNUM EREF 
WHERE EREF.EQUIPMENT_GID = E.EQUIPMENT_GID AND EREF.EQUIPMENT_REFNUM_QUAL_GID LIKE '%PERMANENT DISTRICT%' AND ROWNUM=1), '.',1,1) +1) ), ' PERMANENT DISTRICT','') AS DISTRICT_PSKL_XID, 
**SUBSTR(E.PARK_LOCATION_GID,5,11) AS PARK_LOCATION_GID** FROM EQUIPMENT E 
WHERE E.EQUIPMENT_GID=? 

現在我想檢查空值,在我的子查詢與「ZZZ」取代他們SUBSTR(E.PARK_LOCATION_GID,5,11) AS PARK_LOCATION_GID

任何一個能提出解決方案到這一個。如果您使用的是SQL

+0

這取決於你正在使用,但在某些這將工作'SUBSTR這RDBMS(NVL (E.PARK_LOCATION_GID,'zzz'),5,11)AS PARK_LOCATION_GID' –

+0

我相信nvl是oracle獨有的。但我可能是錯的。 –

回答

0

我得到了它,它應該是:

select E.EQUIPMENT_GID, NVL((SELECT SUBSTR(ES.STATUS_VALUE_GID,INSTR(ES.STATUS_VALUE_GID, '.')+1) FROM EQUIPMENT_STATUS ES WHERE ES.EQUIPMENT_GID=E.EQUIPMENT_GID 
AND ES.STATUS_TYPE_GID LIKE '%EQUIPMENT_STATUS' AND ROWNUM=1),'ZZZ') AS E_STATUS, NVL((SELECT EREF.EQUIPMENT_REFNUM_QUAL_GID FROM EQUIPMENT_REFNUM EREF WHERE EREF.EQUIPMENT_GID = E.EQUIPMENT_GID 
AND EREF.EQUIPMENT_REFNUM_QUAL_GID LIKE '%PERMANENT DISTRICT%' and rownum=1),'ZZZ') AS PERM_DISTRICT_REF, 'PSKL-'||REPLACE(SUBSTR((SELECT EREF.EQUIPMENT_REFNUM_QUAL_GID FROM EQUIPMENT_REFNUM EREF 
WHERE EREF.EQUIPMENT_GID = E.EQUIPMENT_GID AND EREF.EQUIPMENT_REFNUM_QUAL_GID LIKE '%PERMANENT DISTRICT%' AND ROWNUM=1),(INSTR((SELECT EREF.EQUIPMENT_REFNUM_QUAL_GID FROM EQUIPMENT_REFNUM EREF 
WHERE EREF.EQUIPMENT_GID = E.EQUIPMENT_GID AND EREF.EQUIPMENT_REFNUM_QUAL_GID LIKE '%PERMANENT DISTRICT%' AND ROWNUM=1), '.',1,1) +1) ), ' PERMANENT DISTRICT','') AS DISTRICT_PSKL_XID, 
NVL((SUBSTR(E.PARK_LOCATION_GID,5,11)),'ZZZ') AS PARK_LOCATION_GID** FROM EQUIPMENT E 
WHERE E.EQUIPMENT_GID=? 
0

試試這個:

SUBSTR(ISNULL(E.PARK_LOCATION_GID, 'zzz'),5,11) AS PARK_LOCATION_GID