如何在过程中调用函数?

how to call a function in a procedure?

我担心我需要使用必须 return 值的过程调用包主体函数,我可以在 xml 发布者报告 where 子句中使用该值,该子句将调用函数值在报告查询中,我尝试在函数下面的同一主体中编写过程,但困难是我无法调用函数和 return 值。

CREATE OR REPLACE PACKAGE BODY XXMTZ_WO_STG_REP_TRI_TEST
AS
   FUNCTION before_report
      RETURN BOOLEAN
   IS
   --
   BEGIN
      --
      fnd_file.put_line (fnd_file.LOG, 'Entering the IF Block');

      --
      IF     data_source = p_datasource
         AND p_module = 'AP'
         AND p_processing_status = 'Processed'
      THEN
         --
         LP_REP_WHERE := d_process_flag = 'P' AND d_ap_flag = 'P';
      ELSIF     data_source = p_datasource
            AND p_module = 'AP'
            AND p_processing_status = 'Un Processed'
      THEN
         LP_REP_WHERE := d_process_flag = 'P' AND d_ap_flag = 'Y';
      ELSIF     data_source = p_datasource
            AND p_module = 'AP'
            AND p_processing_status = 'ERROR'
      THEN
         LP_REP_WHERE := d_process_flag = 'P' AND d_ap_flag = 'E';
      ELSIF     data_source = p_datasource
            AND p_module = 'AP'
            AND p_processing_status = 'DELETED'
      THEN
         LP_REP_WHERE := d_process_flag = 'R';
      ELSIF     data_source = p_datasource
            AND p_module = 'AR'
            AND p_processing_status = 'Processed'
      THEN
         --
         LP_REP_WHERE := d_process_flag = 'P' AND d_ar_flag = 'P';
      ELSIF     data_source = p_datasource
            AND p_module = 'AR'
            AND p_processing_status = 'Un Processed'
      THEN
         LP_REP_WHERE := d_process_flag = 'P' AND d_ar_flag = 'Y';
      ELSIF     data_source = p_datasource
            AND p_module = 'AR'
            AND p_processing_status = 'ERROR'
      THEN
         LP_REP_WHERE := d_process_flag = 'P' AND d_ar_flag = 'E';
      ELSIF     data_source = p_datasource
            AND p_module = 'AR'
            AND p_processing_status = 'DELETED'
      THEN
         LP_REP_WHERE := d_process_flag = 'R';
      ELSIF     data_source = p_datasource
            AND p_module = 'MTE'
            AND p_processing_status = 'Processed'
      THEN
         --
         LP_REP_WHERE := d_process_flag = 'P' AND d_mte_flag = 'P';
      ELSIF     data_source = p_datasource
            AND p_module = 'MTE'
            AND p_processing_status = 'Un Processed'
      THEN
         LP_REP_WHERE := d_process_flag = 'P' AND d_mte_flag = 'Y';
      ELSIF     data_source = p_datasource
            AND p_module = 'MTE'
            AND p_processing_status = 'ERROR'
      THEN
         LP_REP_WHERE := d_process_flag = 'P' AND d_mte_flag = 'E';
      ELSIF     data_source = p_datasource
            AND p_module = 'MTE'
            AND p_processing_status = 'DELETED'
      THEN
         LP_REP_WHERE := d_process_flag = 'R';
      ELSIF     data_source = p_datasource
            AND p_module = 'Pre Interface'
            AND p_processing_status = 'Processed'
      THEN
         --
         LP_REP_WHERE := d_process_flag = 'P';
      ELSIF     data_source = p_datasource
            AND p_module = 'Pre Interface'
            AND p_processing_status = 'Un Processed'
      THEN
         LP_REP_WHERE := d_process_flag = 'N';
      ELSIF     data_source = p_datasource
            AND p_module = 'Pre Interface'
            AND p_processing_status = 'ERROR'
      THEN
         LP_REP_WHERE := d_process_flag = 'E';
      ELSIF     data_source = p_datasource
            AND p_module = 'Pre Interface'
            AND p_processing_status = 'DELETED'
      THEN
         LP_REP_WHERE := d_process_flag = 'R';
      END IF;

      --
      fnd_file.put_line (fnd_file.LOG, 'EXIT of IF Block');
      RETURN TRUE;
   --
   END before_report;

END XXMTZ_WO_STG_REP_TRI_TEST;

两个问题:

  1. 请确保您的 before_report 函数已在程序包的规范部分中定义。

  2. BOOLEAN 类型在 SQL 中不可用。如果您想从 SQL 语句调用此函数,您需要 return 类似 'Y' 或 'N' 的内容作为 VARCHAR2 值。

编辑

如果你想定义一个过程来调用你的函数,你会做类似的事情

CREATE OR REPLACE PACKAGE XXMTZ_WO_STG_REP_TRI_TEST AS  -- package spec
  PROCEDURE PROC_TO_CALL_FUNCTION;
  FUNCTION BEFORE_REPORT RETURN BOOLEAN;
END XXMTZ_WO_STG_REP_TRI_TEST;
/

CREATE OR REPLACE PACKAGE BODY XXMTZ_WO_STG_REP_TRI_TEST AS  -- package body
  PROCEDURE PROC_TO_CALL_FUNCTION
  IS
    bValue  BOOLEAN;
  BEGIN
    bValue := XXMTZ_WO_STG_REP_TRI_TEST.BEFORE_REPORT;
  END PROC_TO_CALL_FUNCTION;

  FUNCTION BEFORE_REPORT
      RETURN BOOLEAN
  IS
  BEGIN
    -- function body goes here

    RETURN TRUE;
  END BEFORE_REPORT;
END XXMTZ_WO_STG_REP_TRI_TEST;
/