Pl/sql if 语句
Pl/sql if statement
我熟悉 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:
我想做的是 运行 基于条件的查询
例如 - 如果是本月的第一天,则 select * 来自 stackdb
如果是本月 5 日,则 select * 来自 adiffdb 等
这不是因为 if 语句,而是因为您需要为 select 中的值指定一个结果变量。否则您只会执行一个虚拟查询。
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;
我熟悉 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:
我想做的是 运行 基于条件的查询
例如 - 如果是本月的第一天,则 select * 来自 stackdb 如果是本月 5 日,则 select * 来自 adiffdb 等
这不是因为 if 语句,而是因为您需要为 select 中的值指定一个结果变量。否则您只会执行一个虚拟查询。
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;