如何在oracle中获取内部过程的输出

时间:2019-05-14 09:39:28

标签: oracle procedure

我有一个过程在调用另一个过程。如果我自己调用内部过程,则可以得到输出。但是,如果我使用外部过程调用内部过程,我似乎无法获得输出。

外部过程

PROCEDURE APPLY_EXEMPTION_BIDIR_BY_ID (
  O_ERRORCODE OUT NUMBER,
  O_ERRORTEXT OUT VARCHAR2,
  O_SPA OUT VARCHAR2,
  O_SPN OUT VARCHAR2,
  O_FPA OUT VARCHAR2,
  O_FPN OUT VARCHAR2,
  I_CMID IN NUMBER
)
AS
  CMCount NUMBER DEFAULT 0;
  CMNotFound EXCEPTION;
BEGIN

  SELECT COUNT(*) INTO CMCount FROM CCP.v_comms_matrices WHERE id = I_CMID;
  IF(CMCount = 0) THEN
    RAISE CMNotFound;
  END IF;

  DECLARE
  O_SPAI VARCHAR(32);
  CURSOR flow_cursor
  IS
    SELECT id
    FROM comms_matrix_data
    WHERE comms_matrix_id = I_CMID
        AND fpa = 'yyy'
        AND fpn = 'xxx'
        AND ROWNUM <= 5;
  BEGIN
    FOR flow_row IN flow_cursor LOOP
      O_SPAI := '';
      O_ERRORCODE := '';
      O_ERRORTEXT := '';
      O_SPA := '';
      O_SPN := '';
      O_FPA := '';
      O_FPN := '';
      CHECK_EXEMPTION_SECURITY_BY_ID(O_ERRORCODE, O_ERRORTEXT, O_SPAI, O_SPN, O_FPA, O_FPN, flow_row.ID);
      dbms_output.put_line('ERRORCODE ' || O_ERRORCODE || ' ERRORTEXT ' || O_ERRORTEXT || ' SPA ' || O_SPAI || ' SPN ' || O_SPN || ' FPA ' || O_FPA || ' FPN ' || O_FPN || ' flow_row.ID ' || flow_row.ID);
    END LOOP;
  END;

  COMMIT;

  O_ERRORCODE := 0;
  O_ERRORTEXT := 'Success';
EXCEPTION
WHEN CMNotFound THEN
  O_Errorcode := 101;
  O_Errortext := 'Comms Matrix not found';
WHEN OTHERS THEN
  O_Errorcode := SQLCODE;
  O_Errortext := SQLERRM;
END;

内部程序

当我单独调用它时,此方法有效。我可以成功获取输出。

PROCEDURE CHECK_EXEMPTION_SECURITY_BY_ID (
  O_ERRORCODE OUT NUMBER,
  O_ERRORTEXT OUT VARCHAR2,
  O_SPA OUT VARCHAR2,
  O_SPN OUT VARCHAR2,
  O_FPA OUT VARCHAR2,
  O_FPN OUT VARCHAR2,
  I_FLOWID IN NUMBER
)
AS
  FlowCount NUMBER DEFAULT 0;
  FlowNotFound EXCEPTION;
BEGIN
  O_SPA := '';
  O_SPN := '';
  O_FPA := '';
  O_FPN := '';

  SELECT COUNT(*) INTO FlowCount FROM CCP.comms_matrix_data WHERE id = I_FLOWID;
  IF(FlowCount = 0) THEN
    RAISE FlowNotFound;
  END IF;

  DECLARE
  CURSOR flow_cursor
  IS
  SELECT
  t3.service_id
  ,t3.comms_matrix_id
  ,t4.exemption_id
  ,t4.id
  ,t2.id FLOW_ID
  ,t3.updated_by
  ,t4.soct1_1
  ,t4.soct1_2
  ,t4.soct2_1
  ,t4.soct2_2
  ,t4.soct3_1
  ,t4.soct3_2
  ,t4.soct4_1
  ,t4.soct4_2
  ,t4.s_seczone
  ,t4.s_netzone
  ,t4.s_loczone
  ,t4.doct1_1
  ,t4.doct1_2
  ,t4.doct2_1
  ,t4.doct2_2
  ,t4.doct3_1
  ,t4.doct3_2
  ,t4.doct4_1
  ,t4.doct4_2
  ,t4.d_seczone
  ,t4.d_netzone
  ,t4.d_loczone
  ,t4.protocol
  ,t4.ports
  ,NVL(TO_CHAR(t3.expiry_date), 'Forever') EXPIRY_DATE
  FROM CCP.comms_matrices t1
  INNER JOIN CCP.comms_matrix_data t2 ON (t1.id = t2.comms_matrix_id)
  INNER JOIN CCP.v_exemptions_group t3
    ON ((t3.service_id = t1.service_id) OR (t3.service_id IS NULL)) 
    AND ((t3.comms_matrix_id = t1.id) OR (t3.comms_matrix_id IS NULL))
    AND (t3.status = 'Processed')
    AND ((t3.expiry_date IS NULL) OR (t3.expiry_date <= SYSTIMESTAMP))
  INNER JOIN CCP.v_exemption_policies t4 
    ON (t3.id = t4.exemption_id)
    AND (
      (
            ((t2.src_soct1 <= t4.soct1_1) AND (t2.src_eoct1 <= t4.soct1_2))
        AND ((t2.src_soct2 <= t4.soct2_1) AND (t2.src_eoct2 <= t4.soct2_2))
        AND ((t2.src_soct3 <= t4.soct3_1) AND (t2.src_eoct3 <= t4.soct3_2))
        AND ((t2.src_soct4 <= t4.soct4_1) AND (t2.src_eoct4 <= t4.soct4_2))
      ) OR (
        (t2.src_seczone = t4.s_seczone)
        AND ((t2.src_netzone = t4.s_netzone) OR (t4.s_netzone IS NULL))
        AND ((t2.src_loczone = t4.s_loczone) AND (t4.s_netzone IS NOT NULL) OR (t4.s_loczone IS NULL))
      )
    )
    AND (
      (
            ((t2.dst_soct1 <= t4.doct1_1) AND (t2.dst_eoct1 <= t4.doct1_2))
        AND ((t2.dst_soct2 <= t4.doct2_1) AND (t2.dst_eoct2 <= t4.doct2_2))
        AND ((t2.dst_soct3 <= t4.doct3_1) AND (t2.dst_eoct3 <= t4.doct3_2))
        AND ((t2.dst_soct4 <= t4.doct4_1) AND (t2.dst_eoct4 <= t4.doct4_2))
      ) OR (
        (t2.dst_seczone = t4.d_seczone)
        AND ((t2.dst_netzone = t4.d_netzone) OR (t4.d_netzone IS NULL))
        AND ((t2.dst_loczone = t4.d_loczone) AND (t4.d_netzone IS NOT NULL) OR (t4.d_loczone IS NULL))
      )
    )
    AND (
      ((t4.protocol = t2.protocol) AND (t4.ports = t2.ports))
      OR ((t4.protocol = t2.protocol) AND ((t4.ports = t2.ports) OR (t4.ports IS NULL)))
    )
  WHERE (t2.id = I_FLOWID);
  BEGIN
    FOR flow_row IN flow_cursor LOOP
      O_SPA := 'Exemption';
      O_SPN := 'Exemption #' || flow_row.EXEMPTION_ID || '.' || flow_row.ID || ' - Approved by ' || flow_row.UPDATED_BY || ' until ' || flow_row.EXPIRY_DATE || ' (Note: flow id #' || flow_row.FLOW_ID || ')';
      O_FPA := 'Exemption';
      O_FPN := 'Exemption #' || flow_row.EXEMPTION_ID || '.' || flow_row.ID || ' - Approved by ' || flow_row.UPDATED_BY || ' until ' || flow_row.EXPIRY_DATE || ' (Note: flow id #' || flow_row.FLOW_ID || ')';
    END LOOP;

    --CLOSE flow_cursor;
  END;

  COMMIT;

  O_ERRORCODE := 0;
  O_ERRORTEXT := 'Success';

EXCEPTION
WHEN FlowNotFound THEN
  O_Errorcode := 101;
  O_Errortext := 'Flow not found';
WHEN OTHERS THEN
  O_Errorcode := SQLCODE;
  O_Errortext := SQLERRM;
END;

我使用以下代码在sql developer中运行此程序以调用外部过程

DECLARE
    O_ERRORCODE NUMBER;
    O_ERRORTEXT VARCHAR2(2000);
    O_SPA VARCHAR(32);
    O_SPN VARCHAR(255);
    O_FPA VARCHAR(32);
    O_FPN VARCHAR(255);
  BEGIN


 pkgccpcm.APPLY_EXEMPTION_BIDIR_BY_ID(O_ERRORCODE, O_ERRORTEXT, O_SPA, O_SPN, O_FPA, O_FPN, 79087);

 dbms_output.put_line('');
    dbms_output.put_line('ErrorCode: ' || O_ERRORCODE);
    dbms_output.put_line('ErrorText: ' || O_ERRORTEXT);
    dbms_output.put_line('SPA: ' || O_SPA);
    dbms_output.put_line('SPN: ' || O_SPN);
    dbms_output.put_line('FPA: ' || O_FPA);
    dbms_output.put_line('FPN: ' || O_FPN);
    dbms_output.put_line('');
  END;

这是我进入sql developer的注销信息

ERRORCODE 0 ERRORTEXT Success SPA  SPN  FPA  FPN  flow_row.ID 12521471
ERRORCODE 0 ERRORTEXT Success SPA  SPN  FPA  FPN  flow_row.ID 12521465
ERRORCODE 0 ERRORTEXT Success SPA  SPN  FPA  FPN  flow_row.ID 12521333
ERRORCODE 0 ERRORTEXT Success SPA  SPN  FPA  FPN  flow_row.ID 12521339
ERRORCODE 0 ERRORTEXT Success SPA  SPN  FPA  FPN  flow_row.ID 12521669

ErrorCode: 0
ErrorText: Success
SPA: 
SPN: 
FPA: 
FPN: 

0 个答案:

没有答案