我正在编写一个程序,我需要检查我的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;
原文地址:https://www.jb51.cc/mssql/82711.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。