【问题标题】:How to write IF SELECT without using the into如何在不使用 into 的情况下编写 IF SELECT
【发布时间】:2022-06-23 01:07:12
【问题描述】:

我要执行这条语句

if (select object_type from user_objects where object_name = 'xxx')='PROGRAM' then .......

但问题是我不能在不使用变量的情况下做出这样的声明:

select object_type into ala from user_objects where object_name = 'xxx';
  if ala !='PROGRAM' then ...

您知道如何在不使用带变量的 INTO 的情况下执行第一条语句吗?

谢谢!

【问题讨论】:

  • Postgres 还是 Oracle?这有很大的不同。但是你也不能在 SQL 中使用IF,只能在 PL/SQL 或 PL/pgSQL 中使用

标签: sql database postgresql oracle if-statement


【解决方案1】:

如果有多个object_type <> PROGRAM,您可以使用在 oracle 中使用 for 循环的解决方法,效果相同。

 for rec in (select object_type from user_objects where 
 object_name = 'xxx' and object_type<>'PROGRAM')
 loop
 <statements goes here> 
 end loop;

【讨论】:

    猜你喜欢
    • 2021-09-29
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    相关资源
    最近更新 更多