我有基本查询:
select col1, nvl(col1,to_number(null)) from table1 where colx = :new
更新
基本上,在上传期间我正在检查是否:new
在里面table1.colx
。如果是,我想显示col1
,如果不是null
值(我不能放零)。
nvl(col1,to_number(null)) 将返回空白。您可以将其更改为:nvl(col1,0)。
当 colx = 'abcde' 不在 table1 中时,您的查询将引发 no_data_found 异常。它不会从您的查询中返回结果。
您可以捕获此异常并对其采取行动。
在您的pl/sql中,您需要处理查询结果返回0行的情况,即异常处理:
BEGIN
...
select col1 into my_variable from table1 where colx = :new;
...
EXCEPTION WHEN NO_DATA_FOUND then
<whatever-code-when-there-is-no-data>
...
END;