pl / sql if语句

时间:2015-02-27 23:53:32

标签: sql plsql

我熟悉tsql但不太熟悉plsql如何才能让这个查询在pl sql中运行?

DECLARE 
DATENUM INT := 1;

begin
 if DATENUM = 1 
        then 
             select 'one' as test from dual;
        else 
            select 'two' as test from dual;

end if;

end;

我刚收到以下错误

[Error] Script lines: 1-15 -------------------------
 ORA-06550: line 7, column 14:
PLS-00428: an INTO clause is expected in this SELECT statement
ORA-06550: line 9, column 13:
PLS-00428: an INTO clause is expected in this SELECT statement
 Script line 7, statement line 7, column 14 

eidt:

我想要做的是根据条件运行查询

例如

- 如果它是当月的第一个,那么从stackdb中选择*  如果它是当月的第5天,那么从adiffdb等中选择*

1 个答案:

答案 0 :(得分:2)

这不是由于if语句,而是由于你需要指定一个结果变量来选择值。否则你只是执行一个虚拟查询。

DECLARE 
  DATENUM INT := 1;
  DATENAME varchar2(5);
begin
  if DATENUM = 1 then 
    select 'one' into DATENAME as test from dual;
  else 
    select 'two' into DATENAME as test from dual;
  end if;
end;