--data_string cell_string
--data_time cell_time data_time varchar2(100):='HH24:MI';
--data_date cell_date data_date varchar2(100):='YYYY-MM-DD';
--data_datetime cell_datetime data_datetime varchar2(100):='YYYY-MM-DD HH24:MI';
--data_integer cell_integer data_integer varchar2(100):='999999999999999999999999';
--data_number cell_number data_number varchar2(100):='99,999,999,999,999,999';
--data_finance cell_finance data_finance varchar2(100):='9,999,999,999,999,990.00';
--data_decimal cell_decimal data_decimal varchar2(100):='99,999,999,999,990.0000';
--data_rates cell_rates data_rates varchar2(100):='999,999,990.00000';
CREATE OR REPLACE
PACKAGE COMMON_REPORT_OUTPUT_PKG
IS
cell_string varchar2(800):='mso-number-format:"\@";mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
cell_time varchar2(800):='mso-number-format:"hh\:mm\;\@";mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_time varchar2(100):='HH24:MI';
cell_date varchar2(800):='mso-number-format:"yyyy\/mm\/dd"; mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_date varchar2(100):='YYYY-MM-DD';
cell_datetime varchar2(800):='mso-number-format:"yyyy\/mm\/dd\\ hh\:mm"; mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_datetime varchar2(100):='YYYY-MM-DD HH24:MI';
cell_integer varchar2(800):='mso-number-format:"0_ ";mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_integer varchar2(100):='999999999999999999999999';
cell_number varchar2(800):='mso-number-format:"\#\,\#\#0_ ";mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_number varchar2(100):='99,999,999,999,999,999';
cell_finance varchar2(800):='mso-number-format:"\#\,\#\#0\.00_ ";mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_finance varchar2(100):='9,999,999,999,999,990.00';
cell_decimal varchar2(800):='mso-number-format:"\#\,\#\#0\.0000_ ";mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_decimal varchar2(100):='99,999,999,999,990.0000';
cell_rates varchar2(800):='mso-number-format:"\#\,\#\#0\.00000_ ";mso-background-source:auto;mso-pattern:auto;white-space:nowrap;';
data_rates varchar2(100):='999,999,990.00000';
cell_conner varchar2(800):='border-top:none;border-right:.5pt solid white;border-bottom:1.5pt solid white;border-left:none;background:#4F81BD;mso-pattern:#4F81BD none;';
cell_header varchar2(800):='border-top:none;border-right:.5pt solid white;border-bottom:1.5pt solid white;border-left:none;background:#4F81BD;mso-pattern:#4F81BD none;';
row_header varchar2(800):='border-top:none;border-right:.5pt solid white;border-bottom:.5pt solid white;border-left:none;mso-pattern:#B8CCE4 none;';
row_body varchar2(800):='border-top:none;border-right:.5pt solid white;border-bottom:.5pt solid white;border-left:none;';
top_cell varchar2(800):='height:21px;font-size:14.0px;color:#FFFFFF;vertical-align:middle;font-weight:700;padding:2px;text-decoration:none;text-underline-style:none;text-line-through:none;text-align:left;font-family:宋体;mso-pattern:#B8CCE4 none;';
body_cell varchar2(800):='height:18px;font-size:14.0px;color:black;vertical-align:middle;font-weight:400;padding:1px;text-decoration:none;text-underline-style:none;text-line-through:none;font-family:宋体;mso-pattern:#B8CCE4 none;';
odd varchar2(800):='background:#B8CCE4;';
even varchar2(800):='background:#DBE5F1;';
--�����Ϣ
--P_MSG ��Ҫ�������Ϣ
--P_TYPE ���� 0 ʱ ֻ��� Fnd_File.Put_Line ���
--P_TYPE ���� 1 ʱ ֻ��� Dbms_Output.Put_Line ���
--P_TYPE ���� 2 ʱ ֻ��� Fnd_File.Put_Line��Fnd_File.Put_Line
TYPE TYPE_COLUMN_FORMAT IS RECORD(
C_NUMBER NUMBER(4),
C_FORMAT VARCHAR(50),
C_TOTYPE VARCHAR(50)
);
TYPE TYPE_TABLE_FORMAT IS TABLE OF TYPE_COLUMN_FORMAT;
format_table TYPE_TABLE_FORMAT:=new TYPE_TABLE_FORMAT();
PROCEDURE SET_FORMAT_TABLE(
C_NUMBER NUMBER,
C_FORMAT VARCHAR,
C_TOTYPE VARCHAR);
PROCEDURE SET_FORMAT_TABLE(
P_FORMAT_TABLE IN TYPE_TABLE_FORMAT);
PROCEDURE CLEAR_FORMAT_TABLE;
PROCEDURE PRO_OUTPUT_MSG(
P_MSG IN VARCHAR2,
P_TYPE IN INTEGER);
PROCEDURE PRO_REPORT_OUTPUT(
P_CURSOR IN OUT SYS_REFCURSOR,
P_OUT_TYPE IN INTEGER,
P_TYPE IN INTEGER);
PROCEDURE PRO_REPORT_OUTPUT(
P_STRING IN VARCHAR2,
P_OUT_TYPE IN INTEGER,
P_TYPE IN INTEGER);
PROCEDURE PRO_OUTPUT_COLUMNS(
P_rec_tab IN DBMS_SQL.DESC_TAB,
P_TYPE IN INTEGER);
PROCEDURE PRO_OUTPUT_CELL(
P_col_data IN VARCHAR,
P_col_name IN VARCHAR,
P_class_name IN VARCHAR,
P_class_content IN VARCHAR,
P_OUT_TYPE IN INTEGER,
P_TYPE IN INTEGER);
PROCEDURE PRO_REPORT_OUTPUT_XML(
P_STRING IN VARCHAR2,
P_TYPE IN INTEGER,
P_IN_STRING IN VARCHAR2);
PROCEDURE PRO_REPORT_OUTPUT_HTML(
P_STRING IN VARCHAR2,
P_TYPE IN INTEGER,
P_IN_STRING IN VARCHAR2);
PROCEDURE PRO_OUTPUT_HEADERS(
P_rec_tab IN DBMS_SQL.DESC_TAB,
P_TYPE IN INTEGER);
END COMMON_REPORT_OUTPUT_PKG;
/
CREATE OR REPLACE
PACKAGE body COMMON_REPORT_OUTPUT_PKG
IS
PROCEDURE SET_FORMAT_TABLE(
C_NUMBER NUMBER,
C_FORMAT VARCHAR,
C_TOTYPE VARCHAR)
IS
f_col TYPE_COLUMN_FORMAT;
BEGIN
f_col.C_NUMBER:=C_NUMBER;
f_col.C_FORMAT:=C_FORMAT;
f_col.C_TOTYPE:=C_TOTYPE;
format_table.Extend();
format_table(format_table.count):=f_col;
END SET_FORMAT_TABLE;
PROCEDURE SET_FORMAT_TABLE(
P_FORMAT_TABLE IN TYPE_TABLE_FORMAT)
IS
BEGIN
format_table:=P_FORMAT_TABLE;
END;
PROCEDURE CLEAR_FORMAT_TABLE
IS
BEGIN
format_table.delete;
END;
PROCEDURE PRO_OUTPUT_MSG(
P_MSG IN VARCHAR2,
P_TYPE IN INTEGER)
IS
BEGIN
IF P_TYPE=0 THEN
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, P_MSG);
ELSIF P_TYPE=1 THEN
DBMS_OUTPUT.PUT_LINE(P_MSG);
ELSE
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, P_MSG);
DBMS_OUTPUT.PUT_LINE(P_MSG);
END IF;
EXCEPTION
WHEN OTHERS THEN
Fnd_File.Put_Line(FND_FILE.LOG, 'CUX:' || SQLERRM);
--输出XML 字符
END PRO_OUTPUT_MSG;
PROCEDURE PRO_REPORT_OUTPUT(
P_CURSOR IN OUT SYS_REFCURSOR,
P_OUT_TYPE IN INTEGER,
P_TYPE IN INTEGER)
IS
cur_num NUMBER;
col_cnt PLS_INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
col_name VARCHAR2(400);
col_string VARCHAR2(400);
any_data ANYDATA;
BEGIN
/* Convert to DBMS_SQL cursor... */
cur_num:=dbms_sql.to_cursor_number(P_CURSOR);
dbms_sql.describe_columns(cur_num, col_cnt, rec_tab);
PRO_OUTPUT_COLUMNS(rec_tab,P_TYPE);
END PRO_REPORT_OUTPUT;
PROCEDURE PRO_REPORT_OUTPUT_XML(P_STRING IN VARCHAR2,P_TYPE IN INTEGER,P_IN_STRING IN VARCHAR2)
IS
BEGIN
PRO_OUTPUT_MSG('<?xml version="1.0" encoding="UTF-8" ?>',P_TYPE);
PRO_OUTPUT_MSG('<result>',P_TYPE);
PRO_OUTPUT_MSG('<header>',P_TYPE);
PRO_OUTPUT_MSG(P_IN_STRING,P_TYPE);
PRO_OUTPUT_MSG('</header>',P_TYPE);
PRO_OUTPUT_MSG('<body>',P_TYPE);
PRO_REPORT_OUTPUT(P_STRING,1,P_TYPE);
PRO_OUTPUT_MSG('</body>',P_TYPE);
PRO_OUTPUT_MSG('</result>',P_TYPE);
END PRO_REPORT_OUTPUT_XML;
PROCEDURE PRO_REPORT_OUTPUT_HTML(P_STRING IN VARCHAR2,P_TYPE IN INTEGER,P_IN_STRING IN VARCHAR2)
IS
BEGIN
PRO_OUTPUT_MSG('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',P_TYPE);
PRO_OUTPUT_MSG('<html xmlns="http://www.w3.org/1999/xhtml">',P_TYPE);
PRO_OUTPUT_MSG('<head>',P_TYPE);
PRO_OUTPUT_MSG('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',P_TYPE);
PRO_OUTPUT_MSG('<title>报表</title>',P_TYPE);
PRO_OUTPUT_MSG('<style type="text/css">',P_TYPE);
PRO_OUTPUT_MSG('table{mso-displayed-decimal-separator:"\.";mso-displayed-thousand-separator:"\,";}',P_TYPE);
PRO_OUTPUT_MSG('.cell_string{'||cell_string||'}',P_TYPE);
PRO_OUTPUT_MSG('.cell_time{'||cell_time||'}',P_TYPE);
PRO_OUTPUT_MSG('.cell_date{'||cell_date||'}',P_TYPE);
PRO_OUTPUT_MSG('.cell_number{'||cell_number||'}',P_TYPE);
PRO_OUTPUT_MSG('.cell_conner{'||cell_conner||'}',P_TYPE);
PRO_OUTPUT_MSG('.cell_header{'||cell_header||'}',P_TYPE);
PRO_OUTPUT_MSG('.row_header{'||row_header||'}',P_TYPE);
PRO_OUTPUT_MSG('.row_body{'||row_body||'}',P_TYPE);
PRO_OUTPUT_MSG('.top_cell{'||top_cell||'}',P_TYPE);
PRO_OUTPUT_MSG('</style>',P_TYPE);
PRO_OUTPUT_MSG('</head>',P_TYPE);
PRO_OUTPUT_MSG('<body>',P_TYPE);
PRO_OUTPUT_MSG('<div>',P_TYPE);
PRO_OUTPUT_MSG(P_IN_STRING,P_TYPE);
PRO_OUTPUT_MSG('</div>',P_TYPE);
PRO_OUTPUT_MSG('<table border=0 cellpadding=0 cellspacing=0 style="border-collapse: collapse;table-layout:fixed;">',P_TYPE);
PRO_REPORT_OUTPUT(P_STRING,0,P_TYPE);
PRO_OUTPUT_MSG('</table>',P_TYPE);
PRO_OUTPUT_MSG('</body>',P_TYPE);
PRO_OUTPUT_MSG('</html>',P_TYPE);
END PRO_REPORT_OUTPUT_HTML;
PROCEDURE PRO_REPORT_OUTPUT(
P_STRING IN VARCHAR2,
P_OUT_TYPE IN INTEGER,
P_TYPE IN INTEGER)
IS
cur_exe NUMBER;
cur_num NUMBER;
row_num NUMBER;
col_cnt PLS_INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
is_format INTEGER;
col_name VARCHAR2(400);
col_len PLS_INTEGER;
col_type PLS_INTEGER;
col_data VARCHAR2(32767);
col_string VARCHAR2(400);
col_class VARCHAR2(100);
class_content VARCHAR2(8000);
l_vc2 varchar2(32767);
l_number number;
l_vc varchar(32767);
l_date date;
l_raw raw(32767);
l_ch char;
l_clob clob;
l_blob blob;
l_bfile bfile;
BEGIN
--开启游标
cur_num := dbms_sql.open_cursor;
--游标解析
dbms_sql.parse(cur_num,P_STRING,dbms_sql.NATIVE);
--打开描述
dbms_sql.describe_columns(cur_num, col_cnt, rec_tab);
--定义字段
col_num := rec_tab.first;
IF (col_num IS NOT NULL) THEN
LOOP
col_type :=rec_tab(col_num).col_type;
col_name :=rec_tab(col_num).col_name;
col_len:=rec_tab(col_num).col_max_len;
CASE col_type
when 1 THEN
dbms_sql.define_column(cur_num,col_num,l_vc2,col_len);
when 2 THEN
dbms_sql.define_column(cur_num,col_num,l_number);
when 9 THEN
dbms_sql.define_column(cur_num,col_num,l_vc,col_len);
when 12 THEN
dbms_sql.define_column(cur_num,col_num,l_date);
when 23 THEN
dbms_sql.define_column(cur_num,col_num,l_raw);
when 96 THEN
dbms_sql.define_column(cur_num,col_num,l_ch,col_len);
when 112 THEN
dbms_sql.define_column(cur_num,col_num,l_clob);
when 113 THEN
dbms_sql.define_column(cur_num,col_num,l_blob);
when 114 THEN
dbms_sql.define_column(cur_num,col_num,l_bfile);
END CASE;
col_num := rec_tab.next(col_num);
EXIT WHEN (col_num IS NULL);
END LOOP;
END IF;
--执行游标
cur_exe:= dbms_sql.execute(cur_num);
--输出表头描述
PRO_OUTPUT_COLUMNS(rec_tab ,P_TYPE);
--输出表头
if P_OUT_TYPE=0 then
PRO_OUTPUT_HEADERS(rec_tab ,P_TYPE);
end if;
row_num:=0;
WHILE dbms_sql.fetch_rows(cur_num) != 0 LOOP
row_num:=row_num+1;
if P_OUT_TYPE = 0 then
PRO_OUTPUT_MSG('<tr>',P_TYPE);
else
PRO_OUTPUT_MSG('<rows>',P_TYPE);
end if;
col_num := rec_tab.first;
IF (col_num IS NOT NULL) THEN
LOOP
is_format:=0;
col_type :=rec_tab(col_num).col_type;
col_name :=rec_tab(col_num).col_name;
col_class:='';
if col_num=1 then
class_content:=row_header;
else
class_content:=row_body;
end if;
if mod(row_num,2) = 1 then
class_content:=class_content||odd;
else
class_content:=class_content||even;
end if;
class_content:=class_content||body_cell;
CASE col_type
when 1 THEN
dbms_sql.column_value(cur_num,col_num,l_vc2);
col_data:=l_vc2;
col_class:='cell_string';
when 2 THEN
dbms_sql.column_value(cur_num,col_num,l_number);
for i in 1..format_table.count LOOP
if col_num=format_table(i).C_NUMBER then
is_format:=1;
if format_table(i).C_FORMAT = 'data_integer' then
col_data:=to_char(l_number,data_integer);
elsif format_table(i).C_FORMAT = 'data_number' then
col_data:=to_char(l_number,data_number);
elsif format_table(i).C_FORMAT = 'data_finance' then
col_data:=to_char(l_number,data_finance);
elsif format_table(i).C_FORMAT = 'data_decimal' then
col_data:=to_char(l_number,data_decimal);
elsif format_table(i).C_FORMAT = 'data_rates' then
col_data:=to_char(l_number,data_rates);
else
is_format:=0;
end if;
col_class:=format_table(i).C_TOTYPE;
exit;
end if;
end LOOP;
if is_format=0 then
col_data:=to_char(l_number);
col_class:='cell_number';
end if;
when 9 THEN
dbms_sql.column_value(cur_num,col_num,l_vc);
col_data:=l_vc;
col_class:='cell_string';
when 12 THEN
dbms_sql.column_value(cur_num,col_num,l_date);
for i in 1..format_table.count LOOP
if col_num=format_table(i).C_NUMBER then
is_format:=1;
if format_table(i).C_FORMAT = 'data_time' then
col_data:=to_char(l_date,data_time);
elsif format_table(i).C_FORMAT = 'data_date' then
col_data:=to_char(l_date,data_date);
elsif format_table(i).C_FORMAT = 'data_datetime' then
col_data:=to_char(l_date,data_datetime);
else
is_format:=0;
end if;
col_class:=format_table(i).C_TOTYPE;
exit;
end if;
end LOOP;
if is_format=0 then
col_data:=to_char(l_date);
col_class:='cell_datetime';
end if;
when 23 THEN
dbms_sql.column_value(cur_num,col_num,l_raw);
--l_anydata := ANYDATA.ConvertRaw(l_raw);
--when 96 THEN
--dbms_sql.column_value(cur_num,col_num,l_ch);
--l_anydata := ANYDATA.ConvertChar(l_ch);
-- when 112 THEN
--dbms_sql.column_value(cur_num,col_num,l_clob);
--l_anydata := ANYDATA.ConvertClob(l_clob);
-- when 113 THEN
--dbms_sql.column_value(cur_num,col_num,l_blob);
--l_anydata := ANYDATA.ConvertBlob(l_blob);
--when 114 THEN
--dbms_sql.column_value(cur_num,col_num,l_bfile);
-- l_anydata := ANYDATA.ConvertBFile(l_bfile);
END CASE;
PRO_OUTPUT_CELL(col_data,col_name,col_class,class_content, P_OUT_TYPE,P_TYPE);
col_num := rec_tab.next(col_num);
EXIT WHEN (col_num IS NULL);
END LOOP;
END IF;
if P_OUT_TYPE=0 then
PRO_OUTPUT_MSG('</tr>',P_TYPE);
else
PRO_OUTPUT_MSG('</rows>',P_TYPE);
end if;
END LOOP;
dbms_sql.close_cursor(cur_num);
EXCEPTION
WHEN OTHERS THEN
IF dbms_sql.is_open(cur_num) THEN
dbms_sql.close_cursor(cur_num);
END IF;
RAISE;
END PRO_REPORT_OUTPUT;
PROCEDURE PRO_OUTPUT_ROWS(
P_CURSOR IN OUT SYS_REFCURSOR,
P_TYPE IN INTEGER
)
IS
BEGIN
null;
END PRO_OUTPUT_ROWS;
PROCEDURE PRO_OUTPUT_COLUMNS(
P_rec_tab IN DBMS_SQL.DESC_TAB,
P_TYPE IN INTEGER)
IS
col_num integer;
col_string varchar2(400);
FUNCTION PRO_OUTPUT_COLUMN(
P_REC IN DBMS_SQL.DESC_REC)
RETURN VARCHAR2
IS
resultString VARCHAR2(400);
BEGIN
resultString :='';
resultString :=resultString||' type = "' || P_REC.col_type||'"';
resultString :=resultString||' maxlen = "' || P_REC.col_max_len||'"';
resultString :=resultString||' name = "' || P_REC.col_name||'"';
resultString :=resultString||' name_len = "' || P_REC.col_name_len||'"';
resultString :=resultString||' schema_name= "' || P_REC.col_schema_name||'"';
resultString :=resultString||' schema_name_len= "' || P_REC.col_schema_name_len||'"';
resultString :=resultString||' precision = "' || P_REC.col_precision||'"';
resultString :=resultString||' scale = "' || P_REC.col_scale||'"';
resultString :=resultString||' col_null_ok = ';
IF (P_REC.col_null_ok) THEN
resultString:=resultString||'"True"';
ELSE
resultString:=resultString||'"False"';
END IF;
RETURN(resultString);
END PRO_OUTPUT_COLUMN;
BEGIN
PRO_OUTPUT_MSG('<colgroup>',P_TYPE);
col_num := P_rec_tab.first;
IF (col_num IS NOT NULL) THEN
LOOP
col_string:=PRO_OUTPUT_COLUMN(P_rec_tab(col_num));
PRO_OUTPUT_MSG('<col'||col_string||'/>',P_TYPE);
col_num := P_rec_tab.next(col_num);
EXIT
WHEN (col_num IS NULL);
END LOOP;
END IF;
PRO_OUTPUT_MSG('</colgroup>',P_TYPE);
END PRO_OUTPUT_COLUMNS;
PROCEDURE PRO_OUTPUT_HEADERS(
P_rec_tab IN DBMS_SQL.DESC_TAB,
P_TYPE IN INTEGER)
IS
col_num integer;
class_content varchar2(8000);
col_string varchar2(400);
FUNCTION PRO_OUTPUT_HEADER(
P_class_content IN VARCHAR,
P_REC IN DBMS_SQL.DESC_REC)
RETURN VARCHAR2
IS
resultString VARCHAR2(400);
BEGIN
resultString :='<th style="'||P_class_content||'"> ' || P_REC.col_name || '</th>';
RETURN(resultString);
END PRO_OUTPUT_HEADER;
BEGIN
PRO_OUTPUT_MSG('<tr>',P_TYPE);
col_num := P_rec_tab.first;
IF (col_num IS NOT NULL) THEN
LOOP
if col_num=1 then
class_content:=cell_conner||top_cell;
else
class_content:=cell_header||top_cell;
end if;
col_string:=PRO_OUTPUT_HEADER(class_content,P_rec_tab(col_num));
PRO_OUTPUT_MSG(col_string,P_TYPE);
col_num := P_rec_tab.next(col_num);
EXIT
WHEN (col_num IS NULL);
END LOOP;
END IF;
PRO_OUTPUT_MSG('</tr>',P_TYPE);
END PRO_OUTPUT_HEADERS;
PROCEDURE PRO_OUTPUT_CELL(
P_col_data IN VARCHAR,
P_col_name IN VARCHAR,
P_class_name IN VARCHAR,
P_class_content IN VARCHAR,
P_OUT_TYPE IN INTEGER,
P_TYPE IN INTEGER)
IS
BEGIN
IF P_OUT_TYPE = 0 THEN
PRO_OUTPUT_MSG('<td class='||P_class_name||' style="'||P_class_content||'">',P_TYPE);
PRO_OUTPUT_MSG(P_col_data,P_TYPE);
PRO_OUTPUT_MSG('</td>',P_TYPE);
ELSE
PRO_OUTPUT_MSG('<' || P_col_name || '>',P_TYPE);
PRO_OUTPUT_MSG(P_col_data,P_TYPE);
PRO_OUTPUT_MSG('</'||P_col_name||'>',P_TYPE);
END IF;
END PRO_OUTPUT_CELL;
END COMMON_REPORT_OUTPUT_PKG;