2017-10-06 206 views
1

我試圖返回空或虛擬字符串,如果選擇查詢返回null。我嘗試使用NVL(colum,'dummy')中的虛擬值,但我仍然得到no data found錯誤。 下面是我的嘗試:Oracle nvl無法處理空字符串,即使使用後不爲空

SELECT de.destination INTO l_sub_ent 

    FROM dest de 

    where de.destination='somevalue' AND de.destination IS NOT NULL; 

2.

SELECT COALSECE(de.destination, 'dummy') INTO l_sub_ent 

    FROM dest de 

    where de.destination ='some value'; 

SELECT NVL(de.desc_en, 'dummy') INTO l_sub_ent 

    FROM dest de 

    where de.destination ='some value'; 

回答

2

問題不在於你的de.destinationNULL。沒有關於條件de.destination='somevalue'的記錄。處理它是這樣的。

SELECT Count(1) 
INTO v_count 
FROM dest de 
WHERE de.destination='somevalue'; 

IF v_count > 0 THEN 
    SELECT NVL(de.destination,'dummy') 
    INTO l_sub_ent 
    FROM dest de 
    WHERE de.destination='somevalue'; 
END IF; 
0

我可以用下面來解決:

SELECT NVL(MIN(val), 'dummy') INTO l_sub_ent 

    FROM dest de 

    where de.destination ='some value';