Skip to Main Content

SQL & PL/SQL

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!

Dynamic SQL, bind variable and sub query problems

720788Sep 3 2009 — edited Sep 3 2009
Hi,
Here's a package that compile fine. But when I call the procedure SEGMENTS_VALEURS, I get and error ORA-00904 "ENDATEDU" not a valid identifier.

The two procedure do basicly the same thing. They return from a table the last modified row before a date passed as a parameter, for each value. The table contain the history of modifications. The only difference between the two is that the second one is universal for a lot of table so I pass the name of the queried table in a parameter.

I've based my code from example around the net, but I was'nt able to find one where they used REF CURSOR, sub query with bind variable and dynamic SQL. Can anyone tell me what I'm doing wrong? I suspect it's a basic kind of bad syntax.

CREATE OR REPLACE PACKAGE EXTRACTIONS AS
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE ENTITES_VALEURS(ENDATEDU IN DATE, LECUR IN OUT T_CURSOR);
PROCEDURE SEGMENTS_VALEURS(NOMTABLE IN VARCHAR2, ENDATEDU IN DATE, LECUR IN OUT T_CURSOR);
END EXTRACTIONS;

CREATE OR REPLACE PACKAGE BODY EXTRACTIONS AS
PROCEDURE ENTITES_VALEURS(ENDATEDU IN DATE, LECUR IN OUT T_CURSOR)
IS
V_CUR T_CURSOR;
BEGIN
OPEN V_CUR FOR
SELECT E.VALEUR, E.DESCRIPTION, E.ABREVIATION, E.SOURCE, E.DATE_MODIF,
E.MOTIF, E.DATE_ACTIVE, E.DATE_DESACTIVE
FROM (SELECT VALEUR, MAX(DATE_MODIF) MODIF FROM ENTITES
WHERE DATE_ACTIVE<=ENDATEDU AND (DATE_DESACTIVE>= ENDATEDU OR DATE_DESACTIVE IS NULL)
GROUP BY VALEUR) DERNIER_MODIF, ENTITES E
WHERE E.VALEUR = DERNIER_MODIF.VALEUR AND E.DATE_MODIF = DERNIER_MODIF.MODIF
ORDER BY E.VALEUR;
LECUR := V_CUR;
END ENTITES_VALEURS;

PROCEDURE SEGMENTS_VALEURS(NOMTABLE IN VARCHAR2, ENDATEDU IN DATE, LECUR IN OUT T_CURSOR)
IS
V_CUR T_CURSOR;
BEGIN
OPEN V_CUR FOR
'SELECT E.VALEUR, E.DESCRIPTION, E.SOURCE, E.DATE_MODIF, E.MOTIF, E.DATE_ACTIVE, E.DATE_DESACTIVE ' ||
'FROM (SELECT VALEUR, MAX(DATE_MODIF) MODIF FROM ' || NOMTABLE ||
'WHERE DATE_ACTIVE<=ENDATEDU AND (DATE_DESACTIVE>=ENDATEDU OR DATE_DESACTIVE IS NULL) GROUP BY VALEUR) DERNIER_MODIF, '
|| NOMTABLE || 'E WHERE E.VALEUR = DERNIER_MODIF.VALEUR AND E.DATE_MODIF = DERNIER_MODIF.MODIF ' ||
'ORDER BY E.VALEUR';
LECUR := V_CUR;
END SEGMENTS_VALEURS;
END EXTRACTIONS;

There seems to be missing || on the bold line.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 1 2009
Added on Sep 3 2009
1 comment
803 views