手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle数据库存储过程和存储函数

[日期:2013-04-14] 来源:Linux社区  作者:chrp99 [字体:大 中 小]

建立存储函数的语法:

CREATE [OR REPLACE] FUNCTION函数名(参数列表)

RETURN 函数值类型

AS

PLSQL子程序体;

示例:查询某职工的年收入。

SQL> /**/

/*

查询某职工的总收入

*/

create or replace function queryEmpSalary(empid in number)

return number

as

pSal number; --定义变量保存员工的工资

pComm number; --定义变量保存员工的奖金

begin

select sal,comm into psal,pcomm from emp where empno = empid;

return psal*12+nvl(pcomm,0);

end;

/

Function created

l        函数的调用

SQL> declare

v_sal number;

begin

v_sal:=queryEmpSalary(7934);

dbms_output.put_line('salary is:'|| v_sal);

end;

/

salary is:15600

PL/SQL procedure successfully completed

SQL> begin

dbms_output.put_line('salary is:'|| queryEmpSalary(7934));

end;

/

salary is:15600

PL/SQL procedure successfully completed

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款