Report_報表中Ref Cursor資料來源的概念和用法(案例)

來源:互聯網
上載者:User

標籤:des   cWeb   style   class   blog   code   

2014-06-22 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 FOR10       SELECT user_id, employee_num, user_name, party_type, prefix, full_name11         FROM fnd_user fu, hz_parties hp, hr_employees he12        WHERE fu.person_party_id = hp.party_id13          AND hp.person_identifier = he.employee_id14          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結構體

 

******************** 鮑建立********************

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.