oracle PLSQL 情况下的情况

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5559987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:16:25  来源:igfitidea点击:

PLSQL CASE WHEN CONDITION

sqloracleplsqloracle10gora-00923

提问by Arav

I have two queries.

我有两个疑问。

Query 1.

查询 1。

Below PL/SQL is not working. I want to store the output into varable test1 and test2. It's saying ORA-00923: FROM keyword not found. Not sure what is wrong

下面的 PL/SQL 不起作用。我想将输出存储到变量 test1 和 test2 中。它说的是 ORA-00923: FROM 关键字未找到。不知道出了什么问题

DECLARE    
  file_id NUMBER(10) NOT NULL :=5;
  test1   varchar(100);
  test2   varchar(100);

BEGIN

  DBMS_OUTPUT.PUT_LINE('File Id: ' || file_id);

  SELECT table_name 
    INTO test1,
         (CASE owner
            WHEN 'SYS' THEN  'The owner is SYS'
            WHEN 'SYSTEM' THEN 'The owner is SYSTEM'
          END) 
    INTO test2 
    FROM all_tables 
   WHERE rownum <= 1;

END;

Query 2.

查询 2。

In PL/SQL if i just use the select statement without into clause it's not working. Is it a rule that i need to use into clause. The below one does not work. If i want to spool a output from PL/SQL program do i need to store the output of column into the variable and do a dbms_output?

在 PL/SQL 中,如果我只使用 select 语句而不使用 into 子句,则它不起作用。这是我需要使用 into 子句的规则吗?下面一个不起作用。如果我想从 PL/SQL 程序假脱机输出,我是否需要将列的输出存储到变量中并执行 dbms_output?

DECLARE

  file_id  NUMBER(10) NOT NULL :=5;
  test1 varchar(100);
  test2 varchar(100);

BEGIN

  DBMS_OUTPUT.PUT_LINE('File Id: ' || file_id);

  SELECT table_name,
         CASE owner
           WHEN 'SYS' THEN 'The owner is SYS'
           WHEN 'SYSTEM' THEN 'The owner is SYSTEM'
         END
    FROM all_tables;

END;

回答by Jeffrey Kemp

You only need one INTO clause in a PL/SQL query, for example:

在 PL/SQL 查询中只需要一个 INTO 子句,例如:

SELECT table_name, CASE owner WHEN bla bla ... END
INTO test1, test2
FROM all_tables;