zOs/SQL/CATPLACL

set current application compatibility 'V11R1';
with p as
(
  select *
     from sysibm.sysPlan p
  -- where name like 'R%'
)
, li as
(
  select planName pl, case when location = '' then ''
                  else strip(location) || '.' end
       || strip(collid) || '.' || strip(name) col
      from sysibm.sysPackList pl
)
, lu (pl, lst, la, seq) as
(
  select name, varchar('', 9000), varchar('', 50), 0
      from p
  union all select pl, strip(lst || ' ' || la)
    , (select min(col)
      from li
      where lu.pl = li.pl and lu.la < li.col
      )
    , seq + 1
    from lu where la is not null and seq < 1000
)
, l as
(
  select count(*) cnt, max(seq) seq, lst
    from lu
    where la is null or seq >= 1000
    group by rollup(lst)
)
select cnt, seq, lst
    from l
    order by lst