2017-10-06 315 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'; 
相关问题