/*声明部分,以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
; 从上面的PL/SQL程序段看出,整个PL/SQL块分三部分:声明部分(用declare开头)、执行部分(以begin开头)和异常处理部分(以exception开头)。其中执行部分是必须的,其他两个部分可选。无论PL/SQL程序段的代码量有多大,其基本结构就是由这三部分组成。