zoukankan      html  css  js  c++  java
  • 9.函数

     1 --注意:函数必须有返回值
     2 --创建函数
     3 create or replace function f_emp(p_empno number)
     4  return number
     5 is
     6   --定义存储返回值的变量
     7   v_sal emp.sal%type;
     8 begin
     9   --查询操作
    10   select sal into v_sal from emp where empno=p_empno;
    11   return v_sal;
    12 exception
    13   when no_data_found then
    14    DBMS_OUTPUT.put_line(p_empno||'员工没找到');
    15 end;
    16 /
    17 
    18 --调用函数
    19 set serverout on
    20 declare
    21   --定义变量接受函数的返回值
    22   v_sal emp.sal%type;
    23 begin
    24   --直接调用函数
    25   v_sal:=f_emp(7369);
    26   dbms_output.put_line('7369工资为:'||v_sal);
    27 exception 
    28   when others then
    29     dbms_output.put_line('errors others!!');
    30 end;
    31 /
  • 相关阅读:
    活动安排问题
    完美字符串
    Codeforces Round #696 (Div. 2) 解题报告
    Codeforces 1459D
    Codeforces 25D
    POJ 1847
    LightOJ 1074
    POJ 3159
    POJ 1511
    POJ 1502
  • 原文地址:https://www.cnblogs.com/holly8/p/5701826.html
Copyright © 2011-2022 走看看