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 47 48 49 50
|
FUNCTION lookup_generique (
p_table VARCHAR2,
p_colonne VARCHAR2,
p_var varchar2,
p_error_0 IN INTEGER,
p_error_1 IN INTEGER
)
RETURN BOOLEAN
IS
myquery VARCHAR2 (4000);
istrue BOOLEAN default TRUE;
BEGIN
myquery := 'CREATE OR REPLACE FUNCTION proc_gen RETURN BOOLEAN IS';
myquery := myquery || 'local_gen ' || p_table || '.' || p_colonne || '%TYPE;';
myquery := myquery || 'cursor cursor_gen is select distinct '|| p_colonne||' from '|| p_table|| ';';
myquery := myquery || 'type tref_gen is table of '|| p_table||'.'|| p_colonne||'%type;';
myquery := myquery || 'var_gen tref_gen;';
myquery := myquery || 'istrue boolean := true;';
myquery := myquery || 'begin';
myquery := myquery || 'if local_apprenti.'||p_colonne||'is null then';
myquery := myquery || 'insert into apprenti_upload_error(ara_apprenti_pk,numero_uai,'||p_colonne||')';
myquery := myquery || 'values(local_apprenti.apprenti_pk,apprenti.numero_uai,local_apprenti.'||p_var
|| '(select from description from apprenti_type_error where type_error_pk='||p_error_0||';';
myquery := myquery || 'return false;';
myquery := myquery || 'else';
myquery := myquery || 'open cursor_gen;';
myquery := myquery || 'fetch cursor_gen bulk collect into var_gen;';
myquery := myquery || 'close cursor_gen;';
myquery := myquery || 'for i in var_gen.FIRST .. var_gen.LAST';
myquery := myquery || 'loop';
myquery := myquery || ' if local_apprenti.'||p_colonne||'=var_gen(i) then';
myquery := myquery || ' return true;';
myquery := myquery || ' end if;';
myquery := myquery || 'end loop;';
myquery := myquery || 'insert into apprenti_upload_error(apprenti_pk,numero_uai,'||p_colonne||')';
myquery := myquery || 'values(local_apprenti.apprenti_pk,local_apprenti.numero_uai,local_apprenti.'||p_var
|| '(select from description from apprenti_type_error where type_error_pk='||p_error_1||';';
myquery := myquery || 'return false;';
myquery := myquery || 'end if;';
myquery := myquery || 'end proc_gen';
execute immediate 'begin'||myquery||'(:1,:2,:3,:4);end;'
into istrue
using p_table,p_colonne,p_error_0,p_error_1
;
return istrue;
END lookup_generique; |
Partager