fengzgxing 发表于 2013-1-27 05:12:26

pl/sql cursor的用法

/*声明部分,以declare开头*/
declare
v_id integer;
v_name varchar(20);
cursor c_emp is select * from employee where emp_id=3;
/*执行部分,以begin开头*/
begin
 open c_emp;             --打开游标
 loop
  fetch c_emp into v_id,v_name;  --从游标取数据
  exit when c_emp%notfound ;
 end loop ;
close c_emp;           --关闭游标
dbms_output.PUT_LINE(v_name);
/*异常处理部分,以exception开始*/
exception
 when no_data_found then
  dbms_output.PUT_LINE('没有数据');
end ;
页: [1]
查看完整版本: pl/sql cursor的用法