简体   繁体   中英

SELECT statement in Oracle and SQL Server

I have a SQL Server script like

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

I have done this in Oracle;

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

I am getting an error

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

The whole sql server query is about 500 line which is having may variables declared and assigned.... At the end of the script there is a select statement using many of those variables and multiple tables. How could I get that select statement work in Oracle?

If you want use v_num from decalre block you should rewrite your code follows:

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

If you use follows:

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

you must insert value into parametr v_num

if you want select value from num to v_num you should rewrite you code follows:

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

It should be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM