试图声明一个游标,但我被文件结尾击中了(oracle(sql)

jtw3ybtb  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(314)

我现在正在学习oraclesql,我现在正在使用游标。我知道这是个小问题,可能很容易解决,但我的声明语句导致了一个文件结尾错误(pls-00103)
声明如下: declare cursor CustCursor is select * from Customers where cust_email is null; 任何帮助都会被感激,这可能也是值得知道的,我遵循了sams自学sql的书,仍然得到这些问题。
谢谢您!

hmtdttj4

hmtdttj41#

DECLARE 不能单独存在于宇宙中-它是pl/sql块的一部分,它还需要至少一个dummy 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>

或者,正如埃德·史蒂文斯所说,把一切放在它所属的地方(尽管,结果是一样的):

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>

相关问题