我正在使用SQL*Plus.当我使用以下查询时,它给出错误
Error report:
ORA-06550: line 4, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
Run Code Online (Sandbox Code Playgroud)
询问
declare
id varchar2(80) :='test123';
begin
select test_quote,test_id from order_link where id = 'test123';
end;
Run Code Online (Sandbox Code Playgroud)
Ale*_*ole 14
不知道你为什么要使用PL/SQL块.你没有使用id你声明的,最好给它一个与列名不同的名称,以避免混淆.
您可以在SQL*Plus中声明一个绑定变量,然后选择:
var l_test_quote varchar2(80); -- or whatever type/size you need
var l_test_id varchar2(80);
declare
l_id varchar2(80) :='test123';
begin
select test_quote, test_id
into :l_test_quote, :l_test_id
from order_link
where id = l_id;
end;
/
print l_test_quote
print l_test_id
Run Code Online (Sandbox Code Playgroud)
注意在:块之外定义的变量的引用之前,表明它们是绑定变量.l_id在块内声明,因此它没有前面的:.
在这种情况下,您还可以l_id在块外部进行定义,并在仍然使用绑定变量时避免使用PL/SQL:
var l_id varchar2(80);
exec :l_id := 'test123';
select test_quote, test_id
from order_link
where id = :l_id;
Run Code Online (Sandbox Code Playgroud)
因为主查询不再是PL/SQL(虽然exec是;这只是一行匿名块的简写),但您不需要这样做,select ... into因此您不需要声明这些变量.
| 归档时间: |
|
| 查看次数: |
51127 次 |
| 最近记录: |