[英]PL/SQL: Member of method with “where”
How could I do this: 我该怎么做:
Select values from three different columns into nested table or some other kind of collection... 从三个不同的列中选择值到嵌套表或其他某种集合中...
DECLARE
TYPE blockers_set IS TABLE OF (
employee_ID NUMBER(8),
BLOCKING_GROUP NUMBER(4),
BLOCKING_TYPE NUMBER2(2));
select employee_ID, BLOCKING_GROUP, BLOCKING_TYPE
bulk collect into blockers
from blockers;
...and refer to columns: ...并参考专栏:
if employee_ID not member of blockers where blocking_group = 1
and blocking_type = 2
then <<business logic>>
There can be more than one row for one employee_ID in blockers-collection. 在blockers-collection中,一个employee_ID可以有多行。
This is has to be done with pl/sql. 这必须通过pl / sql完成。
You can do it as follows: 您可以按照以下步骤进行操作:
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;
Execution: 执行:
SQL> /
263427
534366
454562
OK, exists.
PL/SQL procedure successfully completed.
Note that: 注意:
if employee_ID not member of blockers where blocking_group = 1 and blocking_type = 2 如果employee_ID不是blocking_group = 1和blocking_type = 2的阻止者的成员
This is not possible using a Member Funtion
. 使用Member Funtion
是不可能的。 You need to declare a MAP
method, which is rather clunky and would get rather annoying if the object has a lot of attributes(just like your case). 您需要声明一个MAP
方法,该方法很笨重,如果对象具有很多属性(就像您的情况一样),则会很烦人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.