ORACLE_FUNCTION

本文介绍了如何在PL/SQL中定义和使用函数,包括基本语法、示例和删除函数的方法。通过具体实例展示了如何计算指定部门的平均薪资,并提供了异常处理的方法。

FUNCTION:

  DEFINE:函数一般用于计算和返回一个值,可以将经常需要使用的计算或功能写成一个函数。

1.basic syntax

create [or replace] function fun_name [(parameter1[,parameter2])...] return data_type is|as

  [inner_variable]

begin

plsql_sentences;

[exception]

[dowith_sentences;]

end [fun_name];

2.Example Usage

  The sql query below is calculate average in the specify department.

 

create or replace function get_avg_pay(num_deptno number) return number is
num_avg_pay number;
begin
     select avg(sal) into num_avg_pay from emp where deptno=num_deptno;
     return(round(num_avg_pay,2));
excepton
    when no_data_found then
         dbms_output.put_line('This is departmetn not exists');     
         return(0);
end;
/
set serveroutput on
declare
    avg_pay number;
begin
    avg_pay:=get_avg_pay(10);
    dbms_output.put_line('average wage is:'||avg_pay);
end;
/

 


 


 3.Delete Function

  BAISE SYNTAX:

select * from user_objects where object_type='FUNCTION';

drop functon fun_name;

转载于:https://www.cnblogs.com/yjhlsbnf/p/7757989.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值