如何在程序中调用函数?

时间:2019-07-15 20:09:35

标签: oracle oracle-sqldeveloper oracle-ebs oracle-apps

我担心需要在哪个程序中调用程序包主体函数,该程序必须返回可在xml Publisher报表中使用的值,其中子句将在报表查询中调用函数值,并且我尝试编写该程序在该函数下方的同一主体中,但是困难是我无法调用该函数并返回该值。

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 个答案:

答案 0 :(得分:0)

两个问题:

  1. 请确保在包的spec部分中定义了before_report函数。

  2. BOOLEAN类型在SQL中不可用。如果要从SQL语句调用此函数,则需要返回“ 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;
/