oracle cursor小例子

来源:互联网 发布:北京淘宝供货商 编辑:程序博客网 时间:2024/05/21 10:27

Cursor的定义:A cursor is a name for a specific private sql area in which information for processing the specific statement is kept;

为了方便:首先创建一个名为cursor_test的表,同时向其插入3条数据;

语句如下:

create table cursor_test(name varchar2(10),id number);
insert into cursor_test values('test1','1');
insert into cursor_test values('test2','2');
insert into cursor_test values('test3','3');

 

 

declare
cursor myCursor is select * from cursor_test;
v_row cursor_test%rowtype;
begin
      open myCursor;
           loop
                fetch myCursor into v_row;
                exit when myCursor%notfound;
                dbms_output.put_line('名字'||v_row.name);
           end loop;
      close myCursor;
end;

 

0 0