IF 中的多个 Select 语句

发布于 2024-08-11 04:29:31 字数 394 浏览 4 评论 0原文

我可以使用一些帮助来编写报告的 prog./sql 构造。Sql

应该首先检查提示符 &然后决定哪些“select”语句应该运行

类似(伪代码)的内容,

Select ACCT,LOC FROM (

   IF :loc = 'MN' THEN
      Select acc as ACCT,location as LOC
   ELSE IF :loc = 'MA' THEN
      Select accid as ACCT,locid as LOC
   ELSE IF :loc = 'PA' THEN 
      Select accountid as ACCT,location as LOC
   END IF)

上面似乎不起作用。请帮忙!

I could use some help to write a prog./sql construct for a report..

The Sql should first check for the prompt & then decide which "select" statements should run

something like (pseudo-code)

Select ACCT,LOC FROM (

   IF :loc = 'MN' THEN
      Select acc as ACCT,location as LOC
   ELSE IF :loc = 'MA' THEN
      Select accid as ACCT,locid as LOC
   ELSE IF :loc = 'PA' THEN 
      Select accountid as ACCT,location as LOC
   END IF)

the above doesnt seem to work. Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天邊彩虹 2024-08-18 04:29:31

你可以这样做:

Select acc as ACCT,location as LOC 
where :loc = 'MN' 
UNION ALL
Select accid as ACCT,locid as LOC 
where :loc = 'MA' 
UNION ALL
Select accountid as ACCT,location as LOC 
where :loc = 'PA';

You could do this:

Select acc as ACCT,location as LOC 
where :loc = 'MN' 
UNION ALL
Select accid as ACCT,locid as LOC 
where :loc = 'MA' 
UNION ALL
Select accountid as ACCT,location as LOC 
where :loc = 'PA';
涫野音 2024-08-18 04:29:31

怎么样...

select acc,
       case :loc
       When 'MN' then location
       When 'MA' then locid
       When 'PA' then location
       ...
       end
from   ...

或者...

select acc,
       case when :loc in ('MN','PA')
            then location
            When :loc in ('MA',...)
            then locid
            ...
       end
from   ...

这样做会更友好,因为它减少了唯一游标的数量。

How about ...

select acc,
       case :loc
       When 'MN' then location
       When 'MA' then locid
       When 'PA' then location
       ...
       end
from   ...

or ...

select acc,
       case when :loc in ('MN','PA')
            then location
            When :loc in ('MA',...)
            then locid
            ...
       end
from   ...

It would be more friendly to do that because it reduces the number of unique cursors.

千里故人稀 2024-08-18 04:29:31

如果您可以创建自定义 PL/SQL 函数,那么您可以从中返回结果集(所谓的记录表),然后只需从函数中进行选择。请参阅本文

If you can create custom PL/SQL functions, then you can return result set from it (so called table of records) and then just select from function. See this article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文