如何检查 Cursor Expression(select cursor) 是否返回 null?

How to check if Cursor Expression(select cursor) is returning null?

我有一个带有多个内部 select 游标的 select 游标表达式。如果内部游标返回任何值,我想检查最外面的 select 游标。 例如,

SELECT
CURSOR
  (SELECT
   CURSOR
     (SELECT c.cat_name category ,
      CURSOR
        (SELECT
         CURSOR
           (SELECT grp.grpng
            GROUPING ,
                             grp.action_group action_group ,
            CURSOR
              (SELECT
               CURSOR
                 (SELECT header_id ,
                         order_no ,
                         cust_name ,
                         cust_phone ,
                         org ,
                         status `enter code here`,
                         reason
                  FROM headers h
                  WHERE h.header_id = da.header_id ) "G_HEADER"
               FROM dual) "LIST_G_HEADER"
            FROM action_group grp
            WHERE grp.grpng = da.grpng
              AND grp.action_grp = da.action_grp ) "G_ACTION"
         FROM action_rep da
         WHERE da.org = 'test'
           AND da.cat_id = c.cat_id
         ORDER BY category,
         GROUPING,
                  reason ) "LIST_G_ACTION_GROUP"
      FROM dual ) "G_CATEGORY"
   FROM dual ) "LIST_G_CATEGORY" ,
       c.category_name
FROM cat c
ORDER BY c.cat_name

我需要检查 "LIST_G_CATEGORY" 游标的结果是否为空,如果为空则不显示该行。 P.S: 由于查询是在post 急于进行查询,请忽略列名不匹配。

版本:Oracle 11g R2

为了检查游标是否为空,首先应该fetch它。

这意味着您可以创建一个 function(可能使用 SYS_REFCURSOR),当 cursor 是否为空 - 但您应该注意 rowtypecursor return,以便做到这一点。

检查此引用

oracle cursor expression,

similar question on Whosebug,

check sys ref cursor is empty - stackoverflw,

ref cursor rowcount question.