Oracle 自定义过程与函数
来源:互联网 发布:网络霸气情侣名 编辑:程序博客网 时间:2024/06/17 05:42
Oracle 自定义过程与函数
1、自定义过程
1、过程定义
create or replace procedure 名字 ([参数1] [in|out] [type])[is|as]变量声明部分;begin执行部分;exception异常部分;end;
2、实例
1、写一个过程,删除emp表中指定员工记录
create or replace procedure p_delete(empno_ in number) is begin delete from emp where empno = empno_; end;
2、写一个过程,用于计算emp表中指定部门的工资总和,并统计其中的员工数量。
//采用变量输出的方式完成,也可以采用如上方式create or replace procedure p_total_emp(dept_no in number,sum_sal out number,count_emp out number)isbeginselect count(*) into count_emp from emp group by deptno having deptno = dept_no;select sum(sal) into sum_sal from emp group by deptno having deptno = dept_no;end;//声明两个变量SQL> var count_emp number;SQL> var sum_sal number;//执行过程exec p_total_emp(10,:sum_sal,:count_emp);//打印变量当前值SQL> print sum_sal count_emp; SUM_SAL---------- 8750 COUNT_EMP---------- 3
2、自定义函数
1、函数定义
create or replace function [f_name] ([参数1] [in|out] [type])return [return_type][is|as]变量声明begin函数体exception ……return %type;end;
2、实例
1、写一个函数,用于计算emp表中指定部门的工资总和,并统计其中的员工数量。
//函数体create or replace function f_total_emp(dept_no in number,sum_sal out number,count_emp out number)return numberisbeginselect sum(sal) into sum_sal from emp group by deptno having deptno = dept_no;select count(*) into count_emp from emp group by deptno having deptno = dept_no;return 1;end;//变量声明SQL> var sum_sal number;SQL> var count_emp number;SQL> var result number;//执行函数SQL> exec :result := f_total_emp(10,:sum_sal,:count_emp);PL/SQL 过程已成功完成。//打印结果SQL> print sum_sal count_emp; SUM_SAL---------- 8750 COUNT_EMP---------- 3
总结:
1、过程的使用
2、函数的使用
3、系统函数的实现
例如:
select sum(sal) from emp;
关于sum函数传参问题,返回值问题
以及emp表的结果集的传递问题。
0 0
- Oracle 自定义过程与函数
- oracle自定义函数、存储过程
- oracle储存过程与函数
- Oracle存储过程与函数
- oracle 存储过程与函数
- ORACLE函数与存储过程
- Oracle函数与存储过程
- Oracle-存储过程与函数
- oracle函数与存储过程
- Oracle存储过程与函数
- oracle自定义函数和存储过程
- oracle存储过程自定义split函数
- oracle自定义函数、存储过程2
- Oracle存储过程和自定义函数
- oracle存储过程和自定义函数
- Oracle基础 自定义函数和存储过程
- 【Oracle】存储过程(Procedure)与(自定义)函数(Function)的区别
- mysql系列:存储过程与自定义函数
- jade模板引擎(二)
- Unity 和 Visual Studio Code ( VS Code ) 第三弹 - Unity Debugger Extension Preview
- iOS开发动画(Animation)总结
- 30 天学习 30 种新技术系列
- 通过用户名称获取微博id
- Oracle 自定义过程与函数
- Swift 开源(介绍和地址)
- 滑动切换activity
- 发生了一个Oracle错误,但无法从Oracle中检索错误信息的处理
- Eclipse中编写servlet时出现"The import javax.servlet cannot be resolved" 问题解决办法
- httpclient基础
- iOS开发——CF前缀
- 通过偏移将GPS坐标转换成百度坐标--js实现
- Dell PowerEdge R710服务器Centos6.2在线扩容raid