declarecursor curEmployees(v_employee_id varchar2)isselect
salary,
email
from employees
where
employee_id = v_employee_id;
stCurEmp curEmployees%rowtype;
salary_exp Exception;--自定义异常beginopen curEmployees
fetch curEmployees(100)into stCurEmp;--发生异常if stCurEmp.salary <=2000then--抛出异常
raise salary_exp;endif;close curEmployees;
dbms_output.put_line('正常终了');
Exception
--异常处理when salary_exp then
dbms_output.put_line('异常终了');end;
record
多个字段存储到一个变量中(单条查询)
--实例1:把单条查询的多个字段存储到一个record类型中。declare--定义record类型type emp_record is record (
v_sal employees.salary%type,
v_email employees.email%type,
v_hire_date employees.hire_date%type);--创建record类型的对象
v_emp_record emp_record;beginselect
salary,
email,
hire_date
into
v_emp_record
from employees
where
employee_id =100;end;
文章目录语法条件判断(1) if ... then elsif then ... else ... end if;(2) case ... when ... then ... end;循环语句(1)loop ...exit when ... end loop;(2) while ... loop ... end loop;(3) for i in 1...30 loop ...end loop;游标多条查询单条查询异常处理异常处理代码record多个字段存储到一个变量中(单条查询)语法条件判断(1)