说明
· 表函数可接受查询语句或游标作为输入参数,并可输出多行数据。
· 该函数可以平行执行,并可持续输出数据流,被称作管道式输出。
· 应用表函数可将数据转换分阶段处理,并省去中间结果的存储和缓冲表。
优势
1.一些复杂的公用信息,但是建立视图又实现不了,此时可以考虑使用管道输出。
2.涉及运算较多,写个简单SQL实现起来较为麻烦,用table实现就ok了
实例
1.前期工作:
create or replace type ty_row as object ( col1 varchar2(36), col2 varchar2(36), col3 varchar2(36) ); create or replace type ty_table as table of ty_row; |
2.接着定义一个函数,用于获取用户基本信息:
create or replace function f_get_user_info(v_user_id in varchar2 default null) return ty_table as v_user_list ty_table; begin select ty_row(t.user_id, nvl(t.emp_name, t.user_name), t.user_name) bulk collect into v_user_list from t_bs_user t where t.user_id = v_user_id or v_user_id is null; return v_user_list; end f_get_user_info; |
3.使用就很简单了:
select * from table(f_get_user_info('1')) |
上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。