Report_报表中Ref Cursor数据源的概念和用法(案例)
2014-06-22 Created By BaoXinjian
一、摘要
在Report Builder中,有两种数据源取法,一种是基于SQL的,另外一种就是基于Ref Cursor的写法
Ref Cursor在Report Builder 中主要用于一些公用的查询会使用到
比如有多个Report可能会用到同一段SQL或者类似SQL,一般会将这个SQL独立出来作为Ref Cursor放在Package中
当Report调用时,就可以通过调用package中的ref cursor实现查询,而不是讲这段SQL每个report都重复写一遍,当SQL需修改时,也只需改Package中的ref cursor即可
在调用Ref Cursor时,
- 一种只在Package中定义Ref Cursor的栏位结构,具体的查询语句在Report中定义
- 一种在Package中不仅仅定义Ref Cursor的栏位结构,也同时定义了如何查询,在Report中只需输入参数调用该Ref Cursor即可
二、分步解析
案例: 定义一个Employee信息获取公用Ref-Cursor,该查询定义在Package中,可被多个report builder调用共享
Step1. 定义了两种类型的ref_cursor,
- 1. employee_refcursor只定义了结构, 具体的SQL需在report builder中进行复制
- 2. query_employee定义了结构和具体的SQL, 所以Report builder只需传入参数即可
/*定义ref cursor package头*/
CREATE OR REPLACE PACKAGE bxj_ref_cursor_pkg IS
TYPE employee_rec IS RECORD(
user_id FND_USER.USER_ID%TYPE,
employee_num HR_EMPLOYEES.EMPLOYEE_NUM%TYPE,
user_name FND_USER.USER_NAME%TYPE,
party_type HZ_PARTIES.PARTY_TYPE%TYPE,
prefix HR_EMPLOYEES.PREFIX%TYPE,
full_name HR_EMPLOYEES.FULL_NAME%TYPE);
TYPE employee_refcursor IS REF CURSOR RETURN employee_rec;
FUNCTION query_employee(user_id NUMBER) RETURN bxj_ref_cursor_pkg.employee_refcursor;
END;
Step2. 定义ref_cursor查询体的如何返回
1 /*定义ref cursor package 体*/
2 CREATE OR REPLACE PACKAGE BODY bxj_ref_cursor_pkg IS
3
4 FUNCTION query_employee(user_id number)
5 RETURN bxj_ref_cursor_pkg.employee_refcursor IS
6 temp_employee_cursor bxj_ref_cursor_pkg.employee_refcursor;
7 BEGIN
8
9 OPEN temp_employee_cursor FOR
10 SELECT user_id, employee_num, user_name, party_type, prefix, full_name
11 FROM fnd_user fu, hz_parties hp, hr_employees he
12 WHERE fu.person_party_id = hp.party_id
13 AND hp.person_identifier = he.employee_id
14 AND fu.user_name = 'GAVIN';
15
16 RETURN temp_employee_cursor;
17
18 END;
19
20 END;
Step3. 在report builder中的两种Query (SQL Query和Ref Cursor Query)
Step4. Query触发器中返回Ref Cursor结构体
Thanks and Regards
ERP技术讨论群: 288307890
技术交流,技术讨论,欢迎加入
Technology Blog Created By Oracle ERP - 鲍新建
技术交流,技术讨论,欢迎加入
Technology Blog Created By Oracle ERP - 鲍新建