我想用另一个自定义oracle类型MATCHING\u CRITERIA\u列表加入一个表,比如EMPLOYEE。
CREATE OR REPLACE
type CRITERIA as object (
DOB DATETIME,
SALARY NUMBER
);
CREATE OR REPLACE TYPE
MATCHING_CRITERIA_LIST IS TABLE OF CRITERIA;
CREATE TABLE EMPLOYEE{
ID NUMBER PRIMARY KEY NOT NULL,
NAME VARCHAR(20 BYTE),
DOB DATETIME,
SALARY NUMBER
}
我真正想要实现的是,
var allEmployeeList = new List<Employee>();
var filteredList = new List<Employee>();
var matchingCriteria = new List<MatchingCritera>{
new MatchingCritera(){DOB = <date1>, salary = <sal1>},
new MatchingCritera(){DOB = <date2>, salary = <sal2>},
new MatchingCritera(){DOB = <date3>, salary = <sal1>}
}
foreach(var emp in allEmployeeList)
{
foreach(var criteria in matchingCriteria)
{
if(emp.DOB == criteria.DOB && emp.salary = criteria.salary)
{
filteredList.Add(emp);
}
}
}
CREATE OR REPLACE
type IDTYPE as object (
id NUMBER
);
CREATE OR REPLACE
type IDTABLETYPE IS TABLE OF IDTYPE;
CREATE OR REPLACE PROCEDURE GET_FILTERED_EMPLOYEE (
IN_CRITERIA_LIST IN MATCHING_CRITERIA_LIST,
CUR_OUT OUT sys_refcursor
)
IS
V_ID_TABLE IDTABLETYPE;
V_TEMP_ID_COLL EMPLOYEE_ID;
BEGIN
V_ID_TABLE := IDTABLETYPE();
V_TEMP_ID_COLL := EMPLOYEE_ID();
IF IN_CRITERIA_LIST.COUNT > 0 THEN
FOR i IN IN_CRITERIA_LIST.FIRST .. IN_CRITERIA_LIST.LAST
LOOP
SELECT EMP.ID BULK COLLECT INTO V_TEMP_ID_COLL FROM EMPLOYEE EMP WHERE
EMP.DOB = IN_CRITERIA_LIST(i).DOB
AND EMP.SALARY = IN_CRITERIA_LIST(i).SALARY
ORDER BY EMP.ID DESC;
IF (V_TEMP_ID_COLL.COUNT > 0) THEN
FOR j IN V_TEMP_ID_COLL.FIRST .. V_TEMP_ID_COLL.LAST
LOOP
V_ID_TABLE.extend();
V_ID_TABLE(V_ID_TABLE.count) := IDTYPE(TO_NUMBER(V_TEMP_ID_COLL(j)));
END LOOP;
END IF;
END LOOP;
END IF;
OPEN CUR_OUT FOR
SELECT * FROM EMPLOYEE EMP WHERE EMP.ID IN (SELECT * FROM TABLE(V_ID_TABLE));
END;
我想删除IN_CRITERIA_列表上的for循环,因为它会影响性能,并执行以下操作:
SELECT * FROM EMPLOYEE EMP
INNER JOIN MATCHING_CRITERIA_LIST MCL ON
EMP.DOB = MCL.DOB
AND EMP.SALARY = MCL.SALARY
ORDER BY TD.TRANS_DASHBOARD_ID DESC;
有人能指导我如何将自定义UDT表与和oracle表连接起来吗?