1

我正在尝试解决以下问题:

我想做一个选择,当结果为空时,它应该被替换为“空”,否则结果的所有行都应该在那里。喜欢:

if (select has no result)
{
 One Line as result with 'no result'
}
else
{
 post every line of the select result
}

那是我的尝试:

select case when count(*) = 0
   then 'no Entry'
   else Members --all Members should be here
END as Member
from tableMember where Membergroup = 'testgroup';

感谢所有可以帮助我的人!

请向我展示在Oracle中使用查询所需的完整代码

4

3 回答 3

1

甲骨文

DECLARE C INTEGER;
SELECT COUNT(*) INTO C FROM tableMember WHERE Membergroup = 'testgroup';

IF C > 0
THEN
    SELECT * FROM tableMember;
ELSE
    SELECT 'No results!' FROM tableMember;
END IF;

仅限 MS-SQL

IF EXISTS(SELECT * FROM tableMember WHERE Membergroup = 'testgroup')
BEGIN
    SELECT * FROM tableMember
END
ELSE
BEGIN
    SELECT 'No results!'
END
于 2012-08-16T09:48:10.620 回答
1

尝试这个:

DECLARE @counter int

SET  @counter = (select count(*) from tableMember where Membergroup = 'testgroup');

IF (@counter > 0)
BEGIN
     SELECT * FROM Members
END
ELSE
BEGIN
     SELECT 'No results!'
END

问候

于 2012-08-16T09:52:17.847 回答
0

我宁愿在应用程序代码而不是存储过程中这样做。您在这里尝试做的是与用户体验相关的工作,恕我直言,数据库不应该关心这些工作。

于 2012-08-16T09:55:49.497 回答