I have created a function in oracle that accepts a parameter and would return set of records (defined a custom data type in oracle that returns a table). The function is working as expected. My question is how do i integrate the same with the existing select query that I have.
Below are the details of the code.
CREATE OR REPLACE TYPE EmpDetails AS OBJECT
(
EMP_ID NUMBER,
EMP_SUMMARY VARCHAR2(256),
EMP_LOCATION VARCHAR2(20)
);
CREATE OR REPLACE TYPE EmpAttributes IS TABLE OF EmpDetails;
create or replace FUNCTION sf_GetEmpDetails
(
p_EmpID IN NUMBER
) RETURN EmpAttributes
AS
v_EmpID NUMBER;
v_EmpSummary VARCHAR2(256);
v_EmpLocation VARCHAR2(20);
table_results EmpAttributes := EmpAttributes();
BEGIN
table_results := EmpAttributes();
table_results.EXTEND;
SELECT T1.BUG_ID,T2.SUMMARY,T1.LOCATION_NAME INTO v_EmpID,v_EmpSummary,v_EmpLocation FROM EMP_TABLE T1,EMP_ADDITIONAL_INFO T2 WHERE T1.EMP_ID = T2.EMP_ID AND T1.EMP_ID = p_EmpID;
table_results(table_results.LAST) := EmpDetails(v_EmpID,v_EmpSummary,v_EmpLocation);
RETURN table_results;
END;
This is working fine when I call this like mentioned below.
select * from table(sf_GetEmpDetails(100));
Now the same has to be integrated with some query that I have. Like the one mentioned below
SELECT T1.EMP_ID, T1.C1, .. .. T2.C1, ... Have to call the function here by passing the emp id selected above in the query
from t1,t2 where t1.id = t2.id and other conditions..
Please advice how to get this working.
Thanks for your help in advance.