Oracle 和 SQL 服务器中的 SELECT 语句

SELECT statement in Oracle and SQL Server

我有一个 SQL 服务器脚本,例如

declare @num int
begin
--//........while loops/ if conditions...
--//........remove code for simplicity
select num from tbl where cnd = @num;
end

我已经在 Oracle 中完成了;

Declare v_num number;
begin
--//........while loops/ if conditions...
--//........remove code for simplicity
select num from tbl where cnd = v_num;
end;
/

我收到一个错误

PLS-00428: an INTO clause is expected in this SELECT statement

整个 sql 服务器查询大约有 500 行,其中声明并分配了多个变量....在脚本末尾有一个 select 语句使用了其中的许多变量和多个表。我怎样才能使 select 语句在 Oracle 中起作用?

应该是

Declare v_num number;
begin
--//........while loops/ if conditions...
--//........remove code for simplicity
select num from tbl where cnd = :v_num;
end;
/

如果你想从 decalre 块中使用 v_num 你应该重写你的代码如下:

Declare v_num number;
begin
--//........while loops/ if conditions...
--//........remove code for simplicity
select num from tbl where cnd = v_num ;
end;
/

如果你使用如下:

Declare v_num number;
begin
--//........while loops/ if conditions...
--//........remove code for simplicity
select num from tbl where cnd = :v_num ;
end;
/

您必须将值插入参数 v_num

如果你想要 select 值从 numv_num 你应该重写你的代码如下:

Declare v_num number;
begin
--//........while loops/ if conditions...
--//........remove code for simplicity
select num into v_num from tbl;
end;
/