Search code examples
plsqlaggregate-functionsplsqldeveloperpipelined-function

PLS-00653 Error on an empty line (Aggregate/table functions are not allowed in PL/SQL scope)


I'm trying to run a PL/SQL Script I made but I'm getting an error:
PLS-00653: aggregate/table functions are not allowed in PL/SQL scope

The problem here is not the error in itself but the line where it's being thrown from.
Here's my PL/SQL block which throws this error:

DECLARE
    TYPE l_code_arr_typ IS VARRAY(3) OF VARCHAR2(100);
    l_code_arr l_code_arr_typ;
    l_objet    objet_interface_pkg.objet_interface_typ;
    l_resultat CLOB;
    l_valeur   valeur_pkg.valeur_typ;
    l_liens    lien_objet_interface_pkg.lien_objet_interface_tab;
    l_rows NUMBER;
BEGIN
    l_code_arr := l_code_arr_typ('champ.fonctions.dossier.particulier',
                                 'champ.fonctions.region.admin',
                                 'champ.fonctions.ministere.organisme');
    l_resultat := '{';

    FOR l_idx IN 1 .. l_code_arr.count LOOP
        l_objet    := objet_interface_pkg.obtenir_fnc(p_code      => l_code_arr(l_idx),
                                                      p_acron_sys => :acronyme);
        l_resultat := l_resultat || '"' || l_objet.code || '":[';

        l_liens := lien_objet_interface_pkg.obtenir_par_objet_fnc(p_id_objet => l_objet.id_obj);
        FOR l_lien IN (SELECT * FROM TABLE(l_liens)) LOOP
            l_valeur   := valeur_pkg.obtenir_fnc(p_id => l_lien.id_valeur);
            l_resultat := l_resultat || '"' || l_valeur.valeur || '"';

            FOR l_enfant IN (SELECT *
                               FROM TABLE(valeur_pkg.obtenir_enfants_fnc(p_id_parent => l_lien.id_valeur,
                                                                         p_code      => l_valeur.valeur))) LOOP
                l_resultat := l_resultat || ',"' || l_enfant.valeur || '"';
            END LOOP;
        END LOOP;

        l_resultat := l_resultat || '],';
    END LOOP;
    <<<<<<<<<< ERROR THROWN HERE (EMPTY LINE)
    l_resultat := substr(l_resultat, 1, length(l_resultat) - 1) || '}';
    dbms_output.put_line(l_resultat);
END;

The error throws on 34:17 (line:column) which is the fourth line from the end of the code block. As you can see the real problem is that this line is an empty line. Moreover, none of the lines near that empty line contains a call to an aggregate function.
So where's the aggregate/table function's call located?

I'm wondering if the problem really comes from my code or if my PL/SQL Developer is broken.

I hope someone can help me...


Solution

  • I found the solution!

    The problem is that the function lien_objet_interface_pkg.obtenir_par_objet is PIPELINED and a pipelined return cannot be stored in a variable.

    So these 2 lines...

        l_liens := lien_objet_interface_pkg.obtenir_par_objet_fnc(p_id_objet => l_objet.id_obj);
        FOR l_lien IN (SELECT * FROM TABLE(l_liens)) LOOP
    

    ...need to be merge into one single line like so:

        FOR l_lien IN (SELECT * FROM TABLE(lien_objet_interface_pkg.obtenir_par_objet_fnc(p_id_objet => l_objet.id_obj))) LOOP
    

    However, I still don't know why PL\SQL Developer said my error comes from line 34 and It'll probably remain a mystery. If anyone have answer to this mystery, please feel free to let me know.