【发布时间】:2011-08-22 17:43:55
【问题描述】:
我正在编写一个程序,我需要检查我的选择查询是否返回了空记录。 (本例中是否有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;
但是 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;
【问题讨论】:
-
select count(*) 也不是检查行的好方法。请参阅下面的答案以获得更优化的方法
-
您的编辑应该是您问题的答案。
标签: plsql