WEB开发网
开发学院数据库Oracle Oracle概念:异常和游标 阅读

Oracle概念:异常和游标

 2009-06-09 13:15:38 来源:WEB开发网   
核心提示: fetch emp_refcur into emp_job;while emp_refcur%found loopdbms_output.put_line(emp_job.employee_name || ‘’’s job is ’);dbm

fetch emp_refcur into emp_job;

while emp_refcur%found loop

dbms_output.put_line(emp_job.employee_name || ‘’’s job is ’);

dbms_output.put_line(emp_job.job_title);

fetch emp_refcur into emp_job;

end loop;

end;

/

单独select

declare

l_empno emp.EMPLOYEE_ID%type;

-- l_ename emp.ename%type;

begin

select EMPLOYEE_ID

into l_empno

from emp;

--where rownum =1;

dbms_output.put_line(l_empno);

end;

/

使用INTO获取值,只能返回一行。

错误处理:

exception

when then

when then

end;

exception_expression包括:

1. 预定义表达式

2. 用户定义表达式

3. PRAGMA EXCEPTION_INIT

预定义

declare

l_dept departments%rowtype;

begin

l_dept.department_id:=100;

l_dept.department_name:=’HR’;

insert into departments(department_id, department_name)

values(l_dept.department_id, l_dept.department_name);

Exception

When DUP_VAL_ON_INDEX then

Dbms_output.put_line(‘heihei’);

end;

/

DUP_VAL_ON_INDEX 异常

Exception

When DUP_VAL_ON_INDEX then

Dbms_output.put_line…..

自定义:

declare

l_exc exception;

begin

raise l_exc;

exception

上一页  1 2 3 4 5 6  下一页

Tags:Oracle 概念 异常

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接