加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

plsql – PL / SQL检查查询是否返回空

发布时间:2020-12-12 16:13:16 所属栏目:MsSql教程 来源:网络整理
导读:我正在编写一个程序,我需要检查我的select查询是否返回一个空的记录. (在这个例子中是否没有x,y架) 我怎样才能做到这一点? 我试过这个: temp shelves.loadability%TYPE := NULL;BEGINselect loadability into temp from shelves where rownumber = x and co
我正在编写一个程序,我需要检查我的select查询是否返回一个空的记录.
(在这个例子中是否没有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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读