select d.portfolio_seq, d.security_id, d.trans_date 
      from inventory_detail d
        where exists (
        /* 入参为I_PORTFOLIO时。 */
        select null from table(PORTFILIO_LIST_SPLIT(I_PORTFOLIO, ','))t
          where d.portfolio_seq = t.message
            and I_PORTFOLIO <> '-1'
        /* 入参为I_GRP_LIST时:普通群组。 */
        union all
        select c.portfolio_seq from table(PORTFILIO_LIST_SPLIT(I_GRP_LIST, ',')) t1 , inventory_contain c
          where c.inv_grp_seq = t1.message
            and d.portfolio_seq = c.portfolio_seq
            and I_GRP_LIST <> '-1'
        /* 入参为I_GRP_LIST时:通用群组。 */
        union all
        select p.portfolio_seq from portfolio p where not exists ( select null from inventory_contain c where c.portfolio_seq = p.portfolio_seq )
          and p.customer_number in( select g.cus_number from inventory_grp g where g.inv_grp_seq in(
             select t2.message from table(PORTFILIO_LIST_SPLIT(I_GRP_LIST, ',')) t2 where g.status = 'U'))
          and p.portfolio_seq =  d.portfolio_seq 
          and I_GRP_LIST <> '-1')
      and d.ivt in ('IVT_BO', 'IVT_OR_S', 'IVT_KR_S')
      and d.trans_date >= (select s.business_date from system_data s)
      and d.trans_date <= I_TRANS_DATE
      and ((d.security_id = I_SECURITY_ID and I_SECURITY_ID <> '-1') or (I_SECURITY_ID = '-1'))
      and ((I_MARKET_FLAG = '0' and d.first_trade_date > I_TRANS_DATE) or -- 3.4 区分一级市场券、二级市场券出报表
            (I_MARKET_FLAG = '1' and d.first_trade_date <= I_TRANS_DATE) or
            I_MARKET_FLAG = '2') 大神们看看这段代码哪里可以进行调优的优化。真的很着急,万分着急。SQL职场