data export refined after AH updated mip schema
git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@2833 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
@@ -22,20 +22,24 @@ create or replace package body MIP_FILES as
|
|||||||
%param p_column_headers - tables column names be exported as a header
|
%param p_column_headers - tables column names be exported as a header
|
||||||
%param p_delimiter - what is the delimiter value is for each field (default ',')
|
%param p_delimiter - what is the delimiter value is for each field (default ',')
|
||||||
*/
|
*/
|
||||||
PROCEDURE export_table_to_csv(p_table IN VARCHAR2, p_column_headers IN VARCHAR2, p_delimiter IN VARCHAR2 DEFAULT ',') is
|
PROCEDURE export_table_to_csv(p_table IN VARCHAR2,
|
||||||
|
p_column_headers IN VARCHAR2,
|
||||||
|
p_delimiter IN VARCHAR2 DEFAULT ',') is
|
||||||
|
|
||||||
l_select VARCHAR2(2000); --will hold our dynamically created sql query
|
l_select VARCHAR2(2000); --will hold our dynamically created sql query
|
||||||
l_cursor INTEGER DEFAULT dbms_sql.open_cursor; --a handle for each row we loop through
|
l_cursor INTEGER DEFAULT dbms_sql.open_cursor; --a handle for the recordset we can then loop through
|
||||||
l_status INTEGER;
|
l_status INTEGER;
|
||||||
l_return VARCHAR2(4000);
|
l_return VARCHAR2(4000);
|
||||||
l_found BOOLEAN := TRUE;
|
l_found BOOLEAN := TRUE;
|
||||||
l_headers VARCHAR(2000); --used to collect the column headers
|
l_headers VARCHAR(2000); --used to collect the column headers
|
||||||
BEGIN
|
BEGIN
|
||||||
|
dbms_output.put_line('me is here');
|
||||||
-- Build the dynamic SQL statement to get the tables column names
|
-- Build the dynamic SQL statement to get the tables column names
|
||||||
FOR f IN (SELECT column_name
|
FOR f IN (SELECT column_name
|
||||||
FROM user_tab_columns
|
FROM user_tab_columns
|
||||||
WHERE table_name = p_table
|
WHERE table_name = upper(p_table)
|
||||||
ORDER BY column_id) LOOP
|
ORDER BY column_id) LOOP
|
||||||
|
dbms_output.put_line('me is in loop');
|
||||||
--
|
--
|
||||||
-- AG's clever delimiting ensures that the rows from the table are output
|
-- AG's clever delimiting ensures that the rows from the table are output
|
||||||
-- in a nice CSV format
|
-- in a nice CSV format
|
||||||
@@ -56,6 +60,7 @@ BEGIN
|
|||||||
--
|
--
|
||||||
-- Now we have the select, let's execute it
|
-- Now we have the select, let's execute it
|
||||||
--
|
--
|
||||||
|
dbms_output.put_line(l_select);
|
||||||
dbms_sql.parse(l_cursor
|
dbms_sql.parse(l_cursor
|
||||||
,l_select
|
,l_select
|
||||||
,dbms_sql.native);
|
,dbms_sql.native);
|
||||||
@@ -65,13 +70,13 @@ BEGIN
|
|||||||
,l_return
|
,l_return
|
||||||
,4000);
|
,4000);
|
||||||
--
|
--
|
||||||
l_status := dbms_sql.execute(l_cursor);
|
l_status := dbms_sql.execute(l_cursor); --could be used for further manipulation
|
||||||
--
|
--
|
||||||
WHILE (dbms_sql.fetch_rows(l_cursor) > 0) LOOP
|
WHILE (dbms_sql.fetch_rows(l_cursor) > 0) LOOP
|
||||||
--
|
--
|
||||||
IF l_found THEN
|
IF l_found THEN
|
||||||
--
|
--
|
||||||
-- Set the MIME type
|
-- Set the header MIME type
|
||||||
owa_util.mime_header( 'application/octet', FALSE );
|
owa_util.mime_header( 'application/octet', FALSE );
|
||||||
-- Set the name of the file
|
-- Set the name of the file
|
||||||
htp.p('Content-Disposition: attachment; filename="'||lower(p_table)||'.csv"');
|
htp.p('Content-Disposition: attachment; filename="'||lower(p_table)||'.csv"');
|
||||||
@@ -89,6 +94,7 @@ BEGIN
|
|||||||
--
|
--
|
||||||
END IF;
|
END IF;
|
||||||
--
|
--
|
||||||
|
-- Main CSV output
|
||||||
dbms_sql.column_value(l_cursor
|
dbms_sql.column_value(l_cursor
|
||||||
,1
|
,1
|
||||||
,l_return);
|
,l_return);
|
||||||
|
|||||||
Reference in New Issue
Block a user