oracle where嵌套游标,PL/SQL - 嵌套游标 cursor()

SQL> create function f_count(cur_names in sys_refcursor) return

number

2  is

3    v_name test2.name%type;

4    n_count number(5)

:= 0;

5  begin

6    loop

7      fetch cur_names into v_name;

8      exit when cur_names%notfound;

9      n_count := n_count +

1;

10    end loop;

11    return n_count;

12  end f_count;

13

/

函数已创建。

SQL> select id, name

2    from test2

3   where f_count(

cursor( select a from test1 where a = test2.id ) ) = 1;

ID NAME

----------

---------------------------------------------------

4

yuechaotian4

5 yuechaotian5

6 yuechaotian6

SQL> select id, name

2    from test2

3   where f_count(

cursor( select a from test1 where a = test2.id ) ) = 0;

ID NAME

----------

---------------------------------------------------

7

yuechaotian7

8 yuechaotian8

9 yuechaotian9

10

yuechaotian10

SQL> select id, name

2    from test2

3   where f_count(

cursor( select a from test1 where a = test2.id ) ) = 2;

ID NAME

----------

---------------------------------------------------

2

yuechaotian2

3 yuechaotian3

SQL> select id, name

2    from test2

3   where f_count(

cursor( select a from test1 where a = test2.id ) ) = 3;

ID NAME

----------

---------------------------------------------------

1

yuechaotian1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值