oracle过程的开发

来源:百度知道 编辑:UC知道 时间:2024/09/21 04:25:01
本人正在自学oracle10g,请教各位:
1 create or replace procedure add_employee(eno number,
2 name varchar2,sal number,job varchar2 default 'CLERK',
3 dno number)
4 is
5 e_integrity exception;
6 pragma exception_init(e_integrity,-2291);
7 begin
8 insert into emp(empno,ename,sal,job,deptno) values 9 (eno,name,sal,job,dno);
10 exception
11 when dup_val_on_index then
12 raise_application_error(-20000,'雇员号不能重复');
13 when e_integrity then
14 raise_application_error(-20001,'部门号不存在');
15 end;
16/
第2行的job varchar2 default 'CLERK'和第6行的pragma exception_init(e_integrity,-2291);是什么意思?
另:开发过程是输入参数IN和输出参数OUT又说明区别呢?该怎么用?

create or replace procedure query_employee
(eno number,name out varchar2,salary out number)
is
begin
select ename,sal into name,salary from emp where empno=eno;
exception
when no_data_found then
raise_application_error(-20000

1. pragma exception_init(e_integrity,-2291); 是用户自定义异常,看下面调用的就是部门号不存在的时候发生这个异常
2. IN 是输入餐厨,OUT是输出参数,比如你输入a =1,经过计算得到b =2,那么a 就是in,b就是out
3.这个存储过程是有参数的,当你在sqlplus下面执行程序的时候,如果你不定义你要执行的参数,存储过程怎么知道是多少呢?
当然你用plsql,你只要输入
begin
query_employee (eno,name,salary);
end;
就可以得到结果了