匿名PL / SQL块:
DECLARE
CURSOR employees_in_10_cur
IS
SELECT *
FROM ad_week_table
BEGIN
FOR employee_rec
IN employees_in_10_cur
LOOP
DBMS_OUTPUT.put_line(employee_rec.ad_no || ',' || employee_rec.week_no);
END LOOP;
END;
执行此块时,我得到一个丢失的关键字错误。我做错了什么?
答案 0 :(得分:0)
你在光标的末尾错过了一个分号:
CURSOR employees_in_10_cur
IS
SELECT *
FROM ad_week_table;
错误消息将始终显示发生错误的行号。请经常检查并查看该区域。
例如;如果我改变了表,那么我可以运行它,我得到以下内容:
SQL> declare
2
3 cursor employees_in_10_cur is
4 select *
5 from user_tables
6
7 begin
8 for employee_rec in employees_in_10_cur loop
9 dbms_output.put_line (
10 employee_rec.ad_no || ',' || employee_rec.week_no );
11 end loop;
12 end;
13 /
for employee_rec in employees_in_10_cur loop
*
ERROR at line 8:
ORA-06550: line 8, column 8:
PL/SQL: ORA-00905: missing keyword
ORA-06550: line 4, column 5:
PL/SQL: SQL Statement ignored
ORA-06550: line 11, column 4:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
你有3个错误;一个在第8行,因为光标无效,一个在第11行,因为循环没有发生,因为光标无效而第一个在第4行,这表示“语句被忽略”。
答案 1 :(得分:0)
在定义游标查询后放置一个分号;
DECLARE
CURSOR employees_in_10_cur
IS
SELECT *
FROM ad_week_table;
BEGIN
FOR employee_rec
IN employees_in_10_cur
LOOP
DBMS_OUTPUT.put_line (
employee_rec.ad_no || ',' || employee_rec.week_no );
END LOOP;
END;