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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
CREATE OR REPLACE Package Pkg_Ultra_Generique AUTHID CURRENT_USER Is
Type Big_Array_aa Is Table Of Varchar(127) Index By Binary_Integer;
Procedure Lecture_Genrerique (
p_query In Varchar2,
p_array Out Big_Array_aa
);
End;
/
CREATE OR REPLACE Package Body Pkg_Ultra_Generique Is
Procedure Lecture_Genrerique (
p_query In Varchar2,
p_array Out Big_Array_aa
) Is
l_theCursor integer default dbms_sql.open_cursor;
l_columnValue varchar2(4000);
l_status integer;
l_descTbl dbms_sql.desc_tab;
l_colCnt number;
l_ind binary_integer := 0;
Begin
execute immediate
'alter session set
nls_date_format=''dd-mon-yyyy hh24:mi:ss'' ';
dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );
dbms_sql.describe_columns
( l_theCursor, l_colCnt, l_descTbl );
for i in 1 .. l_colCnt loop
dbms_sql.define_column
(l_theCursor, i, l_columnValue, 4000);
end loop;
l_status := dbms_sql.execute(l_theCursor);
while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
for i in 1 .. l_colCnt loop
dbms_sql.column_value
( l_theCursor, i, l_columnValue );
p_array(l_ind+i) := SubStr(To_Char(l_columnValue),1, 127);
end loop;
l_ind := l_ind + l_colCnt;
end loop;
execute immediate
'alter session set nls_date_format=''dd-MON-rr'' ';
exception
when others then
execute immediate
'alter session set nls_date_format=''dd-MON-rr'' ';
raise;
End;
End;
/
declare
-- Non-scalar parameters require additional processing
p_array pkg_ultra_generique.big_array_aa;
begin
-- Call the procedure
pkg_ultra_generique.lecture_genrerique(p_query => 'select employee_id, first_name, last_name from hr.employees',
p_array => p_array);
For i In 1..p_array.Count() Loop
Dbms_output.put_line(p_array(i));
End Loop;
Dbms_output.put_line('-----------------------');
Dbms_output.put_line(p_array.Count());
end;
/ |
Partager