zoukankan      html  css  js  c++  java
  • Oracle-函数

    函数的创建与存储过程类似,但是函数必须有返回值(这一点存储过程没有)

    定义一个函数,用于计算emp中指定某个部门的平均工资:

    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));
    exception
    when no_data_found then
    dbms_output.put_line('该部门编号不存在');
    return(0);
    end;
    /

    调用get_avg_pay,计算部门编号为10的雇员平均工资并输出

    declare
    avg_pay number;
    begin
    avg_pay:=get_avg_pay(10);
    dbms_output.put_line('平均工资为:'||avg_pay);
    end;
    /

    删除函数:

    drop function get_avg_pay;

  • 相关阅读:
    如何找回Oracle所有用户丢失的密码
    数据库范式详解
    lua
    cdn
    初心
    广州
    vim 命令
    git 命令
    Linux琐碎
    汪国真语录
  • 原文地址:https://www.cnblogs.com/xcnblog3035/p/5235940.html
Copyright © 2011-2022 走看看