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

时间:2018-11-16 21:44:07

标签: oracle-apex

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

2 个答案:

答案 0 :(得分:2)

  1. P1_DIVISION_ID时的查询是什么样的?该函数返回空值,因为您未指定一个值,因此返回错误。

  2. 请勿执行select ... into lv_query from dual。只需将字符串分配给变量。

  3. 您的功能执行不了什么,为什么还要这样做呢?为什么不只是对源进行SQL查询呢?

答案 1 :(得分:1)

我建议您使用代码创建一个函数:

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;

然后,在PL/SQL Function Body returning SQL Query中使用此功能:

return get_my_query;