Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01006 (ORA-01006: la variable attachée (bind variable) n'existe pas )
ORA-01006 [message #653868] Wed, 20 July 2016 23:38 Go to next message
pcouas
Messages: 112
Registered: February 2016
Senior Member
Hi

I have error ORA-01006: la variable attachée (bind variable) n'existe pas.
I think problem is with pMonth1 variable in "OPEN cValuationReportMonth FOR v_SQLYEARMONTH USING pYear1,pMonth1,pVessel;"

But i use this variable
MONTHS_BETWEEN (LAST_DAY(TO_DATE ('':pYear1''||'':pMonth1'', ''YYMM'')), LAST_DAY(TO_DATE(va.month, ''YYMM'')))+1 as MYEAR ?

Where is my mistake ?
Regards


 
 FUNCTION F_EXPORT_CONSO_VESSEL(pYear1 IN VARCHAR2,pMonth1 IN VARCHAR2,pVessel LO_VESSEL.VESSEL_uid%TYPE)
               RETURN CURSOR_EXPORT
IS
cValuationReportMonth   CURSOR_EXPORT;
v_SQLYEARMONTH varchar2(4000);
BEGIN
 
    ---- par Annnee  
       v_SQLYEARMONTH :='select 
          MONTHS_BETWEEN (LAST_DAY(TO_DATE ('':pYear1''||'':pMonth1'', ''YYMM'')),  LAST_DAY(TO_DATE(va.month, ''YYMM'')))+1 as MYEAR
           ,sum(NVL(va.AMOUNT_USED,0)) AS  AMOUNT_z01
           ,sum(NVL(va.QUANTITY_USED,0)) AS  QUANTITY_z01
           FROM 
           lo_vessel ve
          ,LO_VALUATION va 
          WHERE 
          (to_char(TO_DATE(va.month, ''YYMM''), ''YY'') = :pYear1 ) 
          and va.VESSEL_UID=ve.VESSEL_UID 
          and ve.vessel_uid=:pVessel
          GROUP BY TO_DATE(va.month, ''YYMM'')
          ORDER BY TO_DATE(va.month, ''YYMM'')';
      --  la boucle par mois 
        OPEN  cValuationReportMonth FOR v_SQLYEARMONTH USING pYear1,pMonth1,pVessel;
 
RETURN cValuationReportMonth;
 
END F_EXPORT_CONSO_VESSEL
Re: ORA-01006 [message #653869 is a reply to message #653868] Thu, 21 July 2016 00:22 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

What I see is you have 4 bind variables in the query text and give only 3 variables.
Of course, you had this error at run time and didn't post how you call it, of course, you don't think it is important, how the way you are calling a function is important?

How many times did we tell you to use SQL*Plus and copy and paste: the creation of the function, the call and execution of your function? How many?

In the end,
1/ if you do what we already told you when you use a string with EXECUTE IMMEDIATE or the like (use dbms_output to display the query) you'd see the error
2/ you do NOT need a string variable for this cursor: nothihg is variable or built in the function.

Re: ORA-01006 [message #653872 is a reply to message #653868] Thu, 21 July 2016 01:39 Go to previous messageGo to next message
pcouas
Messages: 112
Registered: February 2016
Senior Member
Hi,

1 My Company use only SQLDeveloper and i have calling fonction from SQLDevlopper that's why i have error message
i search only a solution to my problem and no controversy, i could not install software on this computer.
2 What do you propose to resolve problem ?

Regards
Re: ORA-01006 [message #653877 is a reply to message #653872] Thu, 21 July 2016 02:32 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

What I posted.

Re: ORA-01006 [message #653880 is a reply to message #653877] Thu, 21 July 2016 03:05 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Bind variables are applied positionally, not by name. The pyear1 parameter is not going to be automatically used for both binds of that name, you need to supply it twice.
That said, as Michel pointed out - nothing here is dynamic so you should just change it to static SQL and then the bind variable problem goes away automatically.
Re: ORA-01006 [message #653885 is a reply to message #653880] Thu, 21 July 2016 04:50 Go to previous message
pcouas
Messages: 112
Registered: February 2016
Senior Member
Hi

Thanks very much

Merci (i am an french JEE so PL/SQL is not my favorit language)
Previous Topic: Logic for displaying below row as first row
Next Topic: Getting Parent and Child from the same table & same column
Goto Forum:
  


Current Time: Thu Apr 25 18:19:37 CDT 2024