Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to add week dynamically in PL/SQL function body returning sql query?

Srini-SOct 30 2019 — edited Nov 7 2019

I have below code in the function. As long as I don't use any variable which is a date, it works. The moment I add date variable, it fails and application results in the interactive report show .ORA-00904: "D"."W6": invalid identifier

The code validation works though and it gets saved without any errors.

Sample code  that is similar to my code:

DECLARE

    VAR1       VARCHAR2(2000) := NULL;

    VAR2       VARCHAR2(2000) := NULL;

VAR3       VARCHAR2(2000) := NULL;

VAR99 :=NULL;

   I          NUMBER := 0;

    PREV_SUN   DATE := NULL;

    NEXT_SUN   NUMBER := NULL;

    diff number :=null;

BEGIN

    PREV_SUN   := TO_DATE(NEXT_DAY(

        :P81_END_DT,

        'SUN'

    ) - 7,'DD-MON-YY');

    NEXT_SUN   := to_number(TO_CHAR(TO_DATE(NEXT_DAY(:P81_END_DT,'SUN'),'DD-MON-YY'),'IW'));

    diff:=next_sun-0;

VAR1:= 'select  ';

VAR2:= to_number(diff) || ( 2 + ( I - 1 ) );

VAR3:=' from dual';

VAR99:=VAR1||VAR2||VAR3;

RETURN VAR99;

END;

If VAR2:=( 2 + ( I - 1 ) ); is used, it works because 'diff' is not used. I tried using  the variable in many ways, but no luck yet.

Aren't date functions supported?

This post has been answered by fac586 on Nov 4 2019
Jump to Answer
Comments
Post Details
Added on Oct 30 2019
33 comments
1,564 views