title: oracle apex 18.2 pl/sql function body returning sql query checking page item value
body: <p>I am Creating a interacitve repor <code>pl/sql function body returning sql query</code>
  I have a page item <code>:P1_DIVISION_ID</code>  to pass as parameter as well as check item value is not null as show below</p>
  
  <pre><code>declare
  lv_query varchar2(4000);
  begin
  IF :P1_DIVISION_ID IS NOT NULL THEN
  select 'select DIVISION,
         CUSTOMER_ID,
         PARTY_NAME,
         ACCOUNT_NUMBER,
         ORG_ID,
         OU_NAME,
         AGING_1_30,
         AGING_31_60,
         AGING_61_90,
         ABOVE_90,
         CURRENT_BALANCE,
         PAST_DUE,
         WEBSITE_STATUS,
         BLOCK_DATE,
         BLOCK_REASON,
         TOTAL_NUM_LOGIN,
         CP_LAST_PAY_DT,
         CP_LAST_AMT,
         CP_LAST_PAY_MODE,
         CP_AGE,
         CP_STATUS,
         CP_DATE,
         CP_DEFF,
         CP_UNBILL,
         CP_PHONE,
         CP_EMAIL,
         CP_ACCT_MGR,
         FU_ASSIGN,
         CP_LTR_SENT_DATE,
         CP_LTR_TYPE,
         CP_COMMENTS,
         COMMENTS
    from XX_CUSTOMER_AGING_V WHERE DIVISION '||:P1_DIVISION_ID INTO lv_query
  FROM DUAL;
  END IF;
  
  
  RETURN lv_query;
  
  
  end;
  </code></pre>
  
  <p>BUT when i validate the query it show me the below errors</p>
  
  <p><code>ORA-20999: WWV_FLOW_EXEC.NULL_QUERY_RETURNED_BY_FUNCTION</code></p>
  
  <p>Suggestion required to handle the error</p>