首页 > 解决方案 > 试图声明一个游标,但我被文件结尾击中了!(甲骨文 SQL)

问题描述

我目前正在学习 Oracle SQL,我现在正在使用游标。我知道这是一个小问题,而且可能很容易解决,但我的声明声明正在拉出文件结尾错误。(PLS-00103)

这是声明:

declare cursor CustCursor is select * from Customers where cust_email is null;

任何帮助将不胜感激,也许值得知道我遵循了 Sams 自学 SQL 书并且仍然遇到这些问题。

谢谢!

标签: sqloracleplsqloracle-sqldeveloper

解决方案


DECLARE不能单独存在于宇宙中——它是 PL/SQL 块的一部分,它也至少需要它的虚拟 BEGIN-END部分。

这就是你所拥有的:

SQL> declare cursor CustCursor is select * from Customers where cust_email is null;
  2  /
declare cursor CustCursor is select * from Customers where cust_email is null;
                                                                             *
ERROR at line 1:
ORA-06550: line 1, column 78:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the
following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior

这是你应该拥有的:

SQL> declare cursor CustCursor is select * from Customers where cust_email is null;
  2  begin
  3    null;
  4  end;
  5  /

PL/SQL procedure successfully completed.

SQL>

或者,正如 Ed Stevens 所说,将所有内容放在它所属的位置(尽管结果是一样的):

SQL> declare
  2    cursor CustCursor is select * from Customers where cust_email is null;
  3  begin
  4    null;
  5  end;
  6  /

PL/SQL procedure successfully completed.

SQL>

推荐阅读