/*声明部分,以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 ;
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 ;