My company is implementing an ERP system that uses an Oracle 10g database as its repository. Because this ERP system is being implemented across multiple companies, and because of upgrade and migration issues, none of the objects in the ERP system database can be modified. I'm using Toad as PL/SQL editor.
My responsibility is to create reports to provide information missing from the reports included with the ERP system. No specific formatting is needed for the reports I'm creating, so all that usually needs to be done is to create a SQL statement which is stored in a column in an ad hoc report table. When the SQL
statement is executed, the ERP system automatically creates an interface for the user to assign values to any bind variables, then displays the results in a data grid. The column that stores the SQL statement is limited to 4000 bytes, so if the report is a very complex one, the SQL statement exceeds the length
of the column. Modifications to the existing schema objects, such as changing the column in the ad hoc table to a clob, are not possible for reasons cited above.
One solution to this problem is to create a view that encapsulates each long SQL statement, then select from the view. Unfortunately, this is considered unacceptable because it would result in the creation of dozens or hundreds of views, which would have to be maintained over time as database changes,
upgrades, and migration take place.
The approach I am attempting is to create one large package which includes multiple functions, one for each long SQL statement. A brief SQL statement in the ad hoc table would call the corresponding function in the package, which would return multiple rows. I know this can be done by having either a collection or ref cursor as the function's return type. I need to be able to SELECT FROM the function to access the multiple rows in the collection or ref cursor.
I have been able to successfully SELECT FROM a function returning a ref cursor, which produces a ref cursor. In Toad the results grid displays "(REF CURSOR)", and that column in the results grid can be opened to display the multiple rows within the ref cursor. However, although Toad "understands" the ref cursor, the ERP system does not and cannot accept the ref cursor as input.
I have attempted, but am unable to successfully SELECT FROM a function returning a collection.
My example (function returning collection):
---
CREATE OR REPLACE PACKAGE TEMP_REPORT_PKG IS
TYPE Row_Set IS REF CURSOR;
TYPE Compare_BOM_Row IS RECORD (
eng_level VARCHAR2(10),
eng_part_no VARCHAR2(25),
eng_part_description VARCHAR2(50),
part_state VARCHAR2(1),
eng_qty_assy NUMBER,
eng_uom VARCHAR2(10),
inv_level VARCHAR2(10),
inv_part_no VARCHAR2(25),
inv_part_description VARCHAR2(50),
part_status VARCHAR2(25),
inv_qty_assy NUMBER,
inv_uom VARCHAR2(10)
);
TYPE Compare_BOM IS TABLE OF Compare_BOM_Row;
FUNCTION Compare_Bills_Of_Material (
std_name_ IN VARCHAR2,
part_no_ IN VARCHAR2,
rev_ IN VARCHAR2,
eff_date_ IN DATE,
contract_ IN VARCHAR2,
max_level_ IN NUMBER) RETURN Compare_BOM;
END TEMP_REPORT_PKG;
---
CREATE OR REPLACE PACKAGE BODY TEMP_REPORT_PKG IS
FUNCTION Compare_Bills_Of_Material (
std_name_ IN VARCHAR2,
part_no_ IN VARCHAR2,
rev_ IN VARCHAR2,
eff_date_ IN DATE,
contract_ IN VARCHAR2,
max_level_ IN NUMBER ) RETURN Compare_BOM
IS
temp_ Row_Set;
compare_bom_ Compare_BOM;
BEGIN
OPEN temp_ FOR
...long, complex SELECT FROM statement ...
FETCH temp_ BULK COLLECT INTO compare_bom_;
RETURN compare_bom_;
END Compare_Bills_Of_Material;
END TEMP_REPORT_PKG;
---
If I attempt to consume this function as follows:
SELECT TEMP_REPORT_PKG.Compare_Bills_Of_Material('Company Specific', '5477B-744', 'A', '30-JUN-08','CO001', 3) FROM DUAL
or
SELECT * FROM TABLE (SELECT TEMP_REPORT_PKG.Compare_Bills_Of_Material('Company Specific', '5477B-744', 'A', '30-JUN-08','CO001', 3) FROM DUAL)
I receive ORA-00902: Invalid datatype. How can I SELECT FROM a function that returns a collection or ref cursor?
Thanks in advance,
Bob
SELECT * FROM TABLE(TEMP_REPORT_PKG.Comp