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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
CREATE OR REPLACE PACKAGE BODY PKG_DYNAMIC IS
-------------------------------------------------------------
-- Sample package to test the 100%dynamic Forms features --
-- --
-- Author : Francois Degrelle --
-- --
-------------------------------------------------------------
----------------------------------------------------------
-- Get Datas and data structure from any select Order --
----------------------------------------------------------
PROCEDURE dynamic_cursor
(
PC$Query IN VARCHAR2,
PT$Cols OUT NOCOPY T2,
PT$rows OUT NOCOPY T2,
PC$Where IN VARCHAR2 DEFAULT NULL
)
IS
c NUMBER;
d NUMBER;
col_cnt PLS_INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
LN$Lig PLS_INTEGER := 0 ;
LN$MaxCol PLS_INTEGER := 0 ;
LC$Query VARCHAR2(4000) := PC$Query ;
v VARCHAR2(4000) ;
t T1 ;
source_cursor INTEGER;
result INTEGER;
BEGIN
-- retrieve the columns of the query --
c := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c, LC$Query , dbms_sql.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
LN$MaxCol := rec_tab.LAST ;
FOR i IN rec_tab.FIRST .. rec_tab.LAST LOOP
PT$Cols(i)(1) := rec_tab(i).col_name ; -- name
PT$Cols(i)(2) := rec_tab(i).col_type ; -- type
PT$Cols(i)(3) := rec_tab(i).col_precision ; -- precision
PT$Cols(i)(4) := rec_tab(i).col_scale ; -- scale
PT$Cols(i)(5) := rec_tab(i).col_max_len ; -- length
END LOOP ;
DBMS_SQL.CLOSE_CURSOR(c);
-- Prepare a cursor to select from the source table: --
source_cursor := DBMS_SQL.OPEN_CURSOR;
-- Where clause ? --
IF PC$Where IS NOT NULL THEN
LC$Query := PC$Query || PC$Where ;
END IF ;
DBMS_SQL.PARSE(source_cursor, LC$Query, dbms_sql.NATIVE);
-- Define the columns --
FOR i IN 1 .. LN$MaxCol LOOP
DBMS_SQL.DEFINE_COLUMN(source_cursor, i, v,4000);
END LOOP ;
result := DBMS_SQL.EXECUTE(source_cursor);
-- Fetch the rows from the source query --
LOOP
IF DBMS_SQL.FETCH_ROWS(source_cursor)>0 THEN
-- get column values of the row --
LN$Lig := LN$Lig + 1 ;
FOR i IN 1.. LN$MaxCol LOOP
DBMS_SQL.COLUMN_VALUE(source_cursor, i, t(i));
DBMS_OUTPUT.PUT_LINE(t(i));
PT$rows(LN$Lig)(i) := t(i) ;
END LOOP ;
ELSE
-- No more rows --
EXIT;
END IF;
END LOOP;
DBMS_SQL.CLOSE_CURSOR(source_cursor);
EXCEPTION
WHEN OTHERS THEN
IF DBMS_SQL.IS_OPEN(source_cursor) THEN
DBMS_SQL.CLOSE_CURSOR(source_cursor);
END IF;
RAISE;
END;
-----------------------------------------------
-- Get data structure for any select order --
-----------------------------------------------
PROCEDURE Get_Struct
(
PC$Query IN VARCHAR2,
PT$Cols OUT NOCOPY T2
)
IS
c NUMBER;
d NUMBER;
col_cnt PLS_INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
LN$Lig PLS_INTEGER := 0 ;
LN$MaxCol PLS_INTEGER := 0 ;
v VARCHAR2(4000) ;
t T1 ;
result INTEGER;
BEGIN
-- retrieve the columns of the query --
c := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c, PC$Query , dbms_sql.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
LN$MaxCol := rec_tab.LAST ;
FOR i IN rec_tab.FIRST .. rec_tab.LAST LOOP
PT$Cols(i)(1) := rec_tab(i).col_name ; -- name
PT$Cols(i)(2) := rec_tab(i).col_type ; -- type
PT$Cols(i)(3) := rec_tab(i).col_precision ; -- precision
PT$Cols(i)(4) := rec_tab(i).col_scale ; -- scale
PT$Cols(i)(5) := rec_tab(i).col_max_len ; -- length
END LOOP ;
DBMS_SQL.CLOSE_CURSOR(c);
EXCEPTION
WHEN OTHERS THEN
IF DBMS_SQL.IS_OPEN(c) THEN
DBMS_SQL.CLOSE_CURSOR(c);
END IF;
RAISE;
END Get_Struct;
END PKG_DYNAMIC ;
/ |
Partager