oracle – 在SQL * Plus中声明绑定变量

前端之家收集整理的这篇文章主要介绍了oracle – 在SQL * Plus中声明绑定变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用sql * Plus.当我使用以下查询时,它给出错误
  1. Error report:
  2. ORA-06550: line 4,column 1:
  3. PLS-00428: an INTO clause is expected in this SELECT statement

询问

  1. declare
  2. id varchar2(80) :='test123';
  3. begin
  4. select test_quote,test_id from order_link where id = 'test123';
  5. end;
不知道你为什么要使用PL / sql块.您没有使用您声明的ID,最好给它一个与列名称不同的名称以避免混淆.

您可以在sql * Plus中声明一个绑定变量,然后选择:

  1. var l_test_quote varchar2(80); -- or whatever type/size you need
  2. var l_test_id varchar2(80);
  3.  
  4. declare
  5. l_id varchar2(80) :='test123';
  6. begin
  7. select test_quote,test_id
  8. into :l_test_quote,:l_test_id
  9. from order_link
  10. where id = l_id;
  11. end;
  12. /
  13.  
  14. print l_test_quote
  15. print l_test_id

注意:在引用块之外定义的变量之前,表明它们是绑定变量. l_id在块内声明,因此它没有前面的:.

在这种情况下,您还可以在块外部定义l_id,并在仍然使用绑定变量时避免使用PL / sql

  1. var l_id varchar2(80);
  2.  
  3. exec :l_id := 'test123';
  4.  
  5. select test_quote,test_id
  6. from order_link
  7. where id = :l_id;

因为主查询不再是PL / sql(虽然exec是;这只是一行匿名块的简写),你不需要选择… into所以你不需要声明那些变数.

猜你在找的Oracle相关文章