oracle apex 18.2 pl/sql function body returning sql query checking page item value

落花浮王杯 提交于 2019-12-13 03:33:57

问题


I am Creating a interacitve repor pl/sql function body returning sql query I have a page item :P1_DIVISION_ID to pass as parameter as well as check item value is not null as show below

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;

BUT when i validate the query it show me the below errors

ORA-20999: WWV_FLOW_EXEC.NULL_QUERY_RETURNED_BY_FUNCTION

Suggestion required to handle the error


回答1:


  1. What is the query like when P1_DIVISION_ID? This function is returning a null because you didn't specify one, and hence the error.

  2. Don't do select ... into lv_query from dual. Just assign the string to the variable.

  3. Your function isn't doing much so why are you even doing this? Why not just a SQL query for the source?




回答2:


I would suggest you to create a function with your code:

create or replace function get_my_query return VARCHAR2 
is
lv_query varchar2(4000);
begin
  IF v('P1_DIVISION_ID') IS NOT NULL THEN
    return q'!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!';
  END IF;
end;

and than, use this function in the PL/SQL Function Body returning SQL Query:

return get_my_query;


来源:https://stackoverflow.com/questions/53345834/oracle-apex-18-2-pl-sql-function-body-returning-sql-query-checking-page-item-val

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!