Bonjour,
Voila la question du jour :
Je souhaite créer une fonction qui renvoie une collection, de maniere à pouvoir écrire une requete du style (Select * from ma_fonction)
Alors voila ce que j'ai écris :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 create or replace package PA_COURRIER2 is -- Public type declarations type T_REC_ADR_CORRESP_CLIENT is RECORD ( civ t_clients.cod_civ%type, nom t_clients.lib_nom%type, prenom t_clients.lib_prenomcli%type ); type tab_T_REC_ADR_CORRESP_CLIENT is table of T_REC_ADR_CORRESP_CLIENT index by binary_integer; -- Public constant declarations --<ConstantName> constant <Datatype> := <Value>; -- Public variable declarations --<VariableName> <Datatype>; -- Public function and procedure declarations function FO_ADR_CORRESPONDANT_CLIENT(pnumcli number) return tab_T_REC_ADR_CORRESP_CLIENT; end PA_COURRIER2;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 create or replace package body PA_COURRIER2 is -- Private type declarations -- type <TypeName> is <Datatype>; -- Private constant declarations --<ConstantName> constant <Datatype> := <Value>; -- Private variable declarations -- <VariableName> <Datatype>; -- Function and procedure implementations Function FO_ADR_CORRESPONDANT_CLIENT(pnumcli number) return tab_T_REC_ADR_CORRESP_CLIENT is t_rec tab_T_REC_ADR_CORRESP_CLIENT; i number := 1; cursor cur_courrier is select cli.cod_civ civ, cli.lib_prenomcli prenom, cli.lib_nom nom from op.t_clients cli , op.tr_type_voie typvoi , op.tr_pays pay , op.tr_civilite civ where cli.num_cli = 32686 and cli.cod_typvoi = typvoi.cod_typvoi (+) and cli.cod_pay = pay.cod_pay (+) and civ.cod_civ (+) = cli.cod_civ ; begin for rec in cur_courrier loop t_rec(i).civ := rec.civ; t_rec(i).nom := rec.nom; t_rec(i).prenom := rec.prenom; i:=i+1; end loop; return(t_rec); end FO_ADR_CORRESPONDANT_CLIENT; --begin -- Initialization -- <Statement>; end PA_COURRIER2;
Et voici l'appel
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 select * from table (cast (op.FO_ADR_CORRESPONDANT_CLIENT(32685) as tab_T_REC_ADR_CORRESP_CLIENT) )
Biensur sur il merde lorsque je fais l'appel, et me sort l'erreur :
Et je dois avouer que je me suis inspiré de plusieurs exemples que j'ai trouvé pour écrire mon code et que j'ai l'impression d'etre passé à coté de quelques choses d'essentielles.ORA-22905 cannot access rows from a non-nested table item
Alors si quelqu'un avait une idée je suis preneur.
Merci
Partager