从包DDL中提取多个字符串

时间:2019-04-18 15:12:27

标签: sql oracle

我有一个调度程序包,该程序包将调用过程并将其添加到事件日志表中,具体取决于每月的日期。 (执行此操作的更好方法可能是单独讨论。)我想查询程序包并返回每月的日期和过程名称。

在提取软件包的DDL之后,我试图使用一些REGEXP功能,但无法弄清楚。

SELECT REGEXP...something AS DayOfMonth
     , REGEXP...something AS ProcName
  FROM (
        SELECT DBMS_METADATA.GET_DDL(d.OBJECT_TYPE, d.OBJECT_NAME, 'ME') AS DDL_STR
          FROM DBA_OBJECTS d
         WHERE d.OWNER = 'ME'
           AND d.OBJECT_TYPE = 'PACKAGE'
           AND d.OBJECT_NAME = 'TST_SCHED_PKG'
       ) t
;

子查询DBMS_METADATA.GET_DDL()返回以下CLOB:


  CREATE OR REPLACE EDITIONABLE PACKAGE "ME"."TST_SCHED_PKG2" is

  type run_log_cursor_t is ref cursor return run_log%rowtype;

  procedure run_daily (ioc_run_log_cursor in out run_log_cursor_t);


end TST_SCHED_PKG2;

CREATE OR REPLACE EDITIONABLE PACKAGE BODY "ME"."TST_SCHED_PKG2" is

  procedure run_daily (ioc_run_log_cursor in out run_log_cursor_t) is

    d_run_daily_start_time date;
    d_start date;
    d_end   date;

  begin --run_daily

    d_run_daily_start_time := sysdate;

    --*************************** MONTHLY PROCEDURES HERE ******************************
    case extract (day from d_run_daily_start_time)

      when 1 then

        ABC.PROC1;
             d_end := sysdate;    XYZ.add_event_log('ABC.PROC1',d_start, d_end);    d_start := sysdate;

        ABC.PROC2;
             d_end := sysdate;    XYZ.add_event_log('ABC.PROC2',d_start, d_end);    d_start := sysdate;

      when 2 then

        DEF.PROC3;
             d_end := sysdate;    XYZ.add_event_log('DEF.PROC3',d_start, d_end);    d_start := sysdate;

        GHI.PROC4;
             d_end := sysdate;    XYZ.add_event_log('GHI.PROC4',d_start, d_end);    d_start := sysdate;

      when 3 then

        XYZ.PKG1.PROC5(trunc(sysdate));
        d_end := sysdate;    XYZ.add_event_log('XYZ.PKG1.PROC5',d_start, d_end);    d_start := sysdate;

        XYZ.PKG2.PROC6(add_months(trunc(sysdate, 'mm'), -1));
        d_end := sysdate;    XYZ.add_event_log('XYZ.PKG2.PROC6',d_start, d_end);    d_start := sysdate;

  end; --run_daily

end TST_SCHED_PKG2;

示例包:

create or replace package body TST_SCHED_PKG is

  procedure run_daily (ioc_run_log_cursor in out run_log_cursor_t) is

    d_run_daily_start_time date;
    d_start date;
    d_end   date;

  begin --run_daily

    d_run_daily_start_time := sysdate;

    --*************************** MONTHLY PROCEDURES HERE ******************************
    case extract (day from d_run_daily_start_time)

      when 1 then

        ABC.PROC1;
             d_end := sysdate;    XYZ.add_event_log('ABC.PROC1',d_start, d_end);    d_start := sysdate;

        ABC.PROC2;
             d_end := sysdate;    XYZ.add_event_log('ABC.PROC2',d_start, d_end);    d_start := sysdate;

      when 2 then

        DEF.PROC3;
             d_end := sysdate;    XYZ.add_event_log('DEF.PROC3',d_start, d_end);    d_start := sysdate;

        GHI.PROC4;
             d_end := sysdate;    XYZ.add_event_log('GHI.PROC4',d_start, d_end);    d_start := sysdate;

      when 3 then

        XYZ.PKG1.PROC5(trunc(sysdate));
        d_end := sysdate;    XYZ.add_event_log('XYZ.PKG1.PROC5',d_start, d_end);    d_start := sysdate;

        XYZ.PKG2.PROC6(add_months(trunc(sysdate, 'mm'), -1));
        d_end := sysdate;    XYZ.add_event_log('XYZ.PKG2.PROC6',d_start, d_end);    d_start := sysdate;

  end; --run_daily

end TST_SCHED_PKG;

例如,我想返回:

DayOfMonth ProcName
1          PROC1
1          PROC2
2          PROC3
2          PROC4
3          PKG1.PROC5
3          PKG2.PROC6

0 个答案:

没有答案