sql - 试图声明一个游标,但我被文件结尾击中了!(甲骨文 SQL)
问题描述
我目前正在学习 Oracle SQL,我现在正在使用游标。我知道这是一个小问题,而且可能很容易解决,但我的声明声明正在拉出文件结尾错误。(PLS-00103)
这是声明:
declare cursor CustCursor is select * from Customers where cust_email is null;
任何帮助将不胜感激,也许值得知道我遵循了 Sams 自学 SQL 书并且仍然遇到这些问题。
谢谢!
解决方案
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>
推荐阅读
- powerbi - 如何使用 DAX 而不是快速测量从行总数中计算百分比
- sql-server-2012 - 在预期条件的上下文中指定的非布尔类型的表达式,靠近 [BEGIN]
- arrays - C中的数组故障 - 数组没有超出范围
- c# - C# 我需要一种更有效的方法来检查多个复选框中的值以更改布尔值
- json - JSON 响应格式奇数
- reactjs - 由于未连接表单而取消表单提交 - 控制台错误
- java - cf2016 上的 cfcollection/org.apache.poi 错误,带有一些 .ppsx 文件
- django - 将对象转换为查询集
- python - 如何在 Python 中正确地将非常小的数字从字符串转换为浮点数?
- signal-processing - 将收敛标准转换为 L1 范数