我正在编写一个程序,我需要检查我的select查询是否返回一个空的记录.
(在这个例子中是否没有x,y架)
(在这个例子中是否没有x,y架)
我怎样才能做到这一点?
我试过这个:
temp shelves.loadability%TYPE := NULL; BEGIN select loadability into temp from shelves where rownumber = x and columnnumber = y; IF temp IS NOT NULL THEN /* do something when it's not empty */ ELSE /* do the other thing when it's empty */ END IF;
但是,如果没有工作,第二个分支
编辑:
哦,这样很容易
temp shelves.loadability%TYPE; BEGIN select count(*) into temp from shelves where rownumber = x and columnnumber = y; IF temp != 0 THEN /* do something when it's not empty */ ELSE /* do the other thing when it's empty */ END IF; END;
解决方法
使用异常处理程序
Begin select column into variable from table where ...; -- Do something with your variable exception when no_data_found then -- Your query returned no rows -- when too_many_rows -- Your query returned more than 1 row -- end;