oracle----procedure

--初步认识oracle--procedure,

--1.1创建一个完整的procedure,格式如下

create or replace procedure  procedure_name 

is/as

begin

主体

exception

异常处理主体

end procedure ;

procedure_name 是过程名

or replace  则用来覆盖同过程名的过程的,如果创建的时候,不加or replace 而你创建的过程名又正好存在,就会报错

 参数类型:in

输入型参数,表示这个参数值可以输入给过程,供过程使用,是默认类型,不能进行修改。

参数类型:out

输出型参数,表示这个参数在过程中被赋值,可以提供给过程体以为的部分或环境。

参数类型:in out

输入输出型参数 既可以接收传入的实参值,也可以被子程序修改,可以输出

例如:

create or replace procedure   comunt_num

(in_sex in teaches.sex%type)

 as

out_num number;

begin

if in_sex='M' then

select count(SEX) into out_num from teachers where sex='M';

dbms_output.put_line('number of male teachers:'|| out_num);

else

select count(sex) into out_num from teachers where sex='F';

dbms_output.put_line('number of female teachers:'|| out_number);

end if ;

end conut_num;

1.2储过程的调用:

execute 存储过程名  参数;

1.3存储过程的删除:

drop procedure  存储过程名

猜你喜欢

转载自www.cnblogs.com/supermwb/p/9098912.html
今日推荐