创建过程

---创建过程:

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

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博客 ” ,链接:http://blog.itpub.net/31392094/viewspace-2128376/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31392094/viewspace-2128376/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值