无法从过程调用获取函数值?

时间:2019-07-16 12:47:28

标签: oracle plsql oracle-apps xml-publisher

我已经制作了一个程序包,其中定义了一个过程来调用该函数,并且编写了一个函数以返回varchar2值,但是我无法做到这一点,我不确定为什么我无法做到这一点。除了函数返回值外,即LP_WHERE_REP应该在xml发布者报表查询中使用,以根据选择的参数场景p_module和p_processing_status是参数将条件添加到where子句中。

CREATE OR REPLACE PACKAGE XXMTZ_WO_STG_REP_TRI_TEST AS  -- package spec
p_datasource          VARCHAR2 (40);
p_module              VARCHAR2 (10);
p_processing_status   VARCHAR2 (5);
LP_REP_WHERE VARCHAR2(4000):= NULL;
data_source XXMTZ_AT_AR_WO_STG_TBL.data_source %type;
  PROCEDURE PROC_TO_CALL_FUNCTION;
  FUNCTION BEFORE_REPORT RETURN VARCHAR2;
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  VARCHAR2(4000);
  BEGIN
    dbms_output.put_line('Entered the Procedure');
    bValue := XXMTZ_WO_STG_REP_TRI_TEST.BEFORE_REPORT;
    dbms_output.put_line('procedure end');
  END PROC_TO_CALL_FUNCTION;

  FUNCTION BEFORE_REPORT
      RETURN VARCHAR2
  IS
  BEGIN

    -- function body goes here
    IF     data_source = p_datasource --- p_data_source is parameter value & datasource is table column
         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 LP_REP_WHERE;

  END BEFORE_REPORT;
END XXMTZ_WO_STG_REP_TRI_TEST;
/

1 个答案:

答案 0 :(得分:0)

函数使用变量,例如data_sourcep_datasourcep_module,...,但尚未初始化,因此其值为空。这就是为什么函数不返回 (即NULL)的原因。

也许您的过程应该接受这些参数并将其传递给函数,例如

procedure (p_datasource in varchar2, p_module in varchar2) is
begin
  l_where := function (p_datasource, p_module);
end;

function (p_datasource in varchar2, p_module in varchar2)
  return varchar2;