ITPub博客

首页 > 数据库 > Oracle > 创建过程

创建过程

原创 Oracle 作者:skyin_1603 时间:2016-11-13 23:34:06 0 删除 编辑

---创建过程:

---定义过程的语句格式:

Create or replace procedure procedure_name    --定义过程名

[(argument_name [in |out |in out] procedure_type [,... ...] ) ]  --参数的名字与参数的类型

#in...等关键字是指定参数的模式,in是表示参数输入给过程,out表示参数在过程中将被赋值,in out表示该类型的参数既可以向过程传值,也可以在过程中赋值。

Is | as     --过程的谓语关键词,其中选一个

Begin     --执行部分

   Procedure_body   --过程的主体

End [procedure_name];    --结束过程:

 

--创建一个过程:

hr@PROD>create or replace procedure display_emp(

  2  v_no employees.department_id%type)

  3  as

  4  v_wage employees.salary%type;

  5  v_maxwage employees.salary%type;

  6  v_minwage employees.salary%type;

  7  begin

  8  select avg(salary) into v_wage

  9  from employees where department_id=v_no;

 10  select max(salary) into v_maxwage

 11  from employees where department_id=v_no;

 12  select min(salary) into v_minwage

 13  from employees where department_id=v_no;

 14  

 15  dbms_output.put_line('The average salary is: ' || v_wage);

 16  dbms_output.put_line('The max salary is: ' || v_maxwage);

 17  dbms_output.put_line('The min salary is: ' || v_minwage);

 18  

 19  exception

 20  when no_data_found then

 21  dbms_output.put_line('There is no this department_id!');

 22  end display_emp;

 23  /

Procedure created.

#过程成功创建。

 

--执行过程:

hr@PROD>set serveroutput on

hr@PROD>call display_emp(110);

The average salary is: 10154

The max salary is: 12008

The min salary is: 8300

Call completed.

或者

hr@PROD>execute display_emp(110);

The average salary is: 10154

The max salary is: 12008

The min salary is: 8300

PL/SQL procedure successfully completed.

过程可以保留脚本,频繁使用该查询语句,可以直接调用该过程就打到查询目的。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2128376/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 创建函数
请登录后发表评论 登录
全部评论

注册时间:2016-09-06

  • 博文量
    231
  • 访问量
    215125