.oracle 存储过程创建和调用

存储过程 : 存放在数据库中  执行某种功能的程序,可以包含  一条或多条语句;

 
 创建存储过程:
[] : 表示可以省略的
create  [or  replace] procedure  存储过程名
[(参数名 参数类型  数据类型) ,可以有多个,用逗号隔开]
is 
变量名1 数据类型;
变量名2 数据类型;//这里变量相当于 java的局部变量,
 begin
 语句体;
end ;
 
参数类型:  in  在调用的时候向存储过程里传参的
                    out :相当于java中的返回的数据
                    
示例:
计算三角形的面积
分析 传入两个边长  得到一个面积  假设  n1 是底  n2 是高  
 
create or repalce procedure  One 
(n1 number,n2 number,n3 out number)
is begin
n3 :=n1*n2/2;
end;
调用:
declare 
n1 :=6;
n2 :=4;
n3 number;
begin  One(n1,n2,n3);
end;
_______________________
按员工编号查询emp表的姓名,工资,
 
create or replace procedure  Two
(emp_no number,e_name out varchar2,e_sal out number)
is  begin
select ename,sal into e_name,e_sal from emp where empno=emp_no;
dbms_output.put_line('ename: '||e_name||'  ;   sal :  '||sal);
end ;
 
--------------------------------------------------------
创建无参数的的存储过程
create or replace procedures four 
is 
con number;
begin
select count(1) into con from  emp;
dbms_output.put_line(con);
end;
--------------------------------------------------------
查询存储过程
查询有效的存储过程
select *  from user_procedure;
查询无效的存储过程
 select *from user_objects where status='invalid'  and object_type='procedure';
 
==============================================================
调用存储过程
 1调用无参的 declare begin test; end; 
 2 调用有参的
declare 
   n1 number:=7;n2  number :=4 ;n3 number;
begin
    One(n1,n2,n3);
end;
posted @ 2012-09-14 19:58  Just_Begin  阅读(437)  评论(0编辑  收藏  举报