我试图让任何游标示例正常工作,但是不能让它发生。 IDE:Oracle SQL开发人员 数据库:10g sql oracle
我已经尝试过这三个例子,但它编写得不好。有人能为我提供工作实例吗?
第一个:
编辑:工作!只是在哪里'
DECLARE
CURSOR person_data_cur
as
SELECT *
FROM personal_data
WHERE where name='Karol';
BEGIN
FOR person_data
IN person_data_cur
LOOP
DBMS_OUTPUT.put_line (
person_data.surname);
END LOOP;
END;
和此:
DECLARE my_cursor1 CURSOR FOR
SELECT name, surname
FROM personal_data
WHERE name='Karol';
^错误:
Error report -
ORA-06550: row 1, column 27:
PLS-00103: found symbol "FOR" when expected one of following:
:= . ( @ % ; not null range default character
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
甚至是这样的: 编辑:这一个没关系,只是我的IDE忽略了前两行,并执行了其他...但我猜它没关系,因为它不在任何块或程序中
CURSOR c1
IS
SELECT course_number
FROM courses_tbl
WHERE course_name = name_in;
答案 0 :(得分:0)
对于第二个示例:您的语法不正确。 游标的伪代码是:
Declare
Cursor Cursor_name
is
select * from table where <Conditions>;
Begin
For cur_Rec in cursor_name
Loop
<what you want to do>
End Loop;
End;
对于第三个示例,我认为name_in
是输入参数,请更正语法:
CURSOR c1 (name_in VARCHAR2)
IS
SELECT course_number
FROM courses_tbl
WHERE course_name = name_in;
请参阅Cursor Declaration了解详情