1.使用集合赋值
DECLARE
TYPE t_user_id IS TABLE OF test_forall.user_id%TYPE;
t1 t_user_id;
BEGIN
t1 := t_user_id(1,2,3);
FOR i IN 1..t1.count
LOOP
dbms_output.put_line(t1(i));
END LOOP;
END;
2.set 集合去重
DECLARE
TYPE t_user_id IS TABLE OF test_forall.user_id%TYPE;
t1 t_user_id;
t2 t_user_id;
BEGIN
t1 := t_user_id(1,1,2,2,3,3);
t2 := SET(t1);
FOR i IN 1..t2.count
LOOP
dbms_output.put_line('t2:'||t2(i));
END LOOP;
END;
3.multiset union 合并包含重复值 /multiset union distinct 合并去重复值
DECLARE
TYPE t_user_id IS TABLE OF test_forall.user_id%TYPE;
t1 t_user_id := t_user_id(1,2,3);
t2 t_user_id := t_user_id(1,2,3,4);
BEGIN
t2 := t2 MULTISET UNION DISTINCT t1;
FOR i IN 1..t2.count
LOOP
dbms_output.put_line('t2:'||t2(i));
END LOOP;
END;
4.集合求差
DECLARE
TYPE t_user_id IS TABLE OF test_forall.user_id%TYPE;
t1 t_user_id := t_user_id(1,2,3);
t2 t_user_id := t_user_id(1,2,3,4);
BEGIN
t2 := t2 MULTISET EXCEPT t1;
FOR i IN 1..t2.count
LOOP
dbms_output.put_line('t2:'||t2(i));
END LOOP;
END;
5.检测集合是否为空 if arr is null then 初始化 end if;