你可以这样做:
CREATE TABLE blockers(
employee_id NUMBER(8),
blocking_group NUMBER(4),
blocking_type number(2));
===============================
select * from blockers;
===============================
Create or replace type OBJ_BLOCKERS as OBJECT(
employee_id NUMBER(8),
blocking_group NUMBER(4),
blocking_type number(2)
);
=================================================
Create or replace type varble is table of OBJ_BLOCKERS;
===================================================
DECLARE
--Creating one element for comparision. In your case you need to populate your employee_id to be compared here.
tmp OBJ_BLOCKERS:=OBJ_BLOCKERS(263427,1,2);
var varble;
myid INT;
begin
--This how you Select values from three different columns into nested table(Object)
Select OBJ_BLOCKERS(employee_id,
blocking_group,
blocking_type)
Bulk Collect into var
from blockers;
-- Displaying Employee_Id from the collection
For i in 1..var.count
loop
dbms_output.put_line(var(i).employee_id);
end loop;
--
SELECT 1
INTO myid
FROM TABLE(var) q
where OBJ_BLOCKERS(q.employee_id,q.blocking_group,q.blocking_type) = tmp --Here you are comparing the employee_id which should be a member of collection
AND q.blocking_group = 1;
IF (myid = 1) THEN
dbms_output.put_line('OK, exists.');
END IF;
Exception
When No_DATa_found then
dbms_output.put_line('No Data Found');
End;
执行:
SQL> /
263427
534366
454562
OK, exists.
PL/SQL procedure successfully completed.
注意:
如果employee_ID 不是blockers 的成员,其中blocking_group = 1 和blocking_type = 2
这是不可能的Member Funtion
。您需要声明一个MAP
方法,如果对象具有很多属性(就像您的情况一样),该方法相当笨重并且会变得相当烦人。