zoukankan      html  css  js  c++  java
  • 函数

    ------------------------------------------------函数 begin---------------------------------
    22. 函数的 helloworld: 返回一个 "helloworld--!" 的字符串

    create or replace function helloworld
    return varchar2
    is
    begin
           return 'helloworld--!';
    end;
    
    
    执行函数
    
    
    begin
        dbms_output.put_line(helloworld());
    end;

    23. 定义带参数的函数: 两个数相加

    create or replace function add_func(a number, b number)
    return number
    is
    begin
           return (a + b);
    end;

    执行函数

    begin
        dbms_output.put_line(add_func(12, 13));
    end;

    25. 定义一个函数: 获取给定部门的工资总和, 要求, 部门号定义为参数, 工资总额定义为返回值.

    create or replace function sum_sal(dept_id number)
           return number
           is
           
           cursor sal_cursor is select salary from employees where department_id = dept_id;
           v_sum_sal number(8) := 0;   
    begin
           for c in sal_cursor loop
               v_sum_sal := v_sum_sal + c.salary;
           end loop;       
    
    
           dbms_output.put_line('sum salary: ' || v_sum_sal);
           return v_sum_sal;
    end;

    执行函数

    begin
        dbms_output.put_line(sum_sal(80));
    end;

    26. 关于 OUT 型的参数: 因为函数只能有一个返回值, PL/SQL 程序可以通过 OUT 型的参数实现有多个返回值
    要求: 定义一个函数: 获取给定部门的工资总和 和 该部门的员工总数, 要求: 部门号定义为参数, 工资总额定义为返回值.

    create or replace function sum_sal(dept_id number, total_count out number)
           return number
           is
           
           cursor sal_cursor is select salary from employees where department_id = dept_id;
           v_sum_sal number(8) := 0;   
    begin
           total_count := 0;
    
    
           for c in sal_cursor loop
               v_sum_sal := v_sum_sal + c.salary;
               total_count := total_count + 1;
           end loop;       
    
    
           --dbms_output.put_line('sum salary: ' || v_sum_sal);
           return v_sum_sal;
    end;   

    执行函数:

    declare 
      v_total number(3) := 0;
    
    
    begin
        dbms_output.put_line(sum_sal(80, v_total));
        dbms_output.put_line(v_total);
    end;

    ------------------------------------------------函数 end---------------------------------

  • 相关阅读:
    (转发)storm 入门原理介绍
    shell :将标准输出及标准错误输出写到指定文件
    shell循环(两个日期比较,改变某个特定日期来改变当前比较值)
    MongoDB基本操作
    (转)cenntos 安装mongodb
    通过spark sql 将 hdfs上文件导入到mongodb
    股票实战--线性回归
    Python PIL 的image类和numpy array之间的互换
    根据关键点的脸型的计算
    用反卷积(Deconvnet)可视化理解卷积神经网络还有使用tensorboard
  • 原文地址:https://www.cnblogs.com/nbkyzms/p/5031430.html
Copyright © 2011-2022 走看看