CoreApiHtml.sql -2<-- (INVItemCt115h.sql ) Note: 223702.1
CoreApiHtml.sql
-- Function Name: Display_SQL
--
-- Usage:
-- a_number := Display_SQL('SQL statement','Name for Header','Long Flag',
-- 'Feedback','Max Rows','Indent Level');
--
-- Parameters:
-- SQL Statement - Any valid SQL Select Statement
-- Name for Header - Text String to for heading the output
-- Long Flag - Y or N - If set to N then this will not output
-- any LONG columns (default = Y)
-- Feedback - Y or N indicates whether to indicate the number of rows
-- selected automatically in the output (default = Y)
-- Max Rows - Limits the number of rows output to this number. NULL or
-- ZERO value indicates unlimited. (Default = NULL)
-- Indent Level - Indicates if the table should be indented and if so
-- how far: 0 = no indent, 1=.25in, 2=.5in, 3 = .75in
-- (Default = 0)
--
-- Returns:
-- The function returns the # of rows selected.
-- If there is an error then the function returns -1.
--
-- Output:
-- Displays the output of the SQL statement as an HTML table.
--
-- Examples:
-- declare
-- num_rows number;
-- begin
-- num_rows := Display_SQL('select * from ar_system_parameters_all',
-- 'AR Parameters', 'Y', 'N',null);
-- num_rows := Display_SQL('select * from pa_implementations_all',
-- 'PA Implementation Options');
-- end;
--
function Display_SQL (p_sql_statement varchar2
, table_alias varchar2
, display_longs varchar2default'Y'
, p_feedback varchar2default'Y'
, p_max_rows number defaultnull
, p_ind_level number default0
, p_current_exec numberdefault0)returnnumberis
error_position number;
error_position_end number;
row_counter number;
hold_exclude_cols boolean;
hold_sql_needed varchar2(3);
hold_string varchar2(32767) defaultnull;
hold_option varchar2(32767) defaultnull;
hold_sql varchar2(32767) defaultnull;
hold_sql_remain varchar2(32767) defaultnull;
hold_element varchar2(32767) defaultnull;
hold_long long;
hold_clob clob;
hold_length varchar2(40);
hold_bgcolor varchar2(40);
hold_color varchar2(40);
hold_open_paren number;
hold_curr_loc number;
hold_end_pos number;
column_counter binary_integer default1;
value_counter binary_integer default1;
column_high binary_integer default1;
value_high binary_integer default1;
v_cursor_id number;
v_dummy integer;
l_hold_length varchar2(20);
l_hold_date_format varchar2(40);
l_hold_type varchar2(40);
l_max_rows integer;
l_feedback_txt varchar2(200);
v_values V2T;
v_options V2T;
v_describe dbms_sql.desc_tab;
T_VARCHAR2 constantinteger:=1;
T_NUMBER constantinteger:=2;
T_LONG constantinteger:=8;
T_ROWID constantinteger:=11;
T_DATE constantinteger:=12;
T_RAW constantinteger:=23;
T_CHAR constantinteger:=96;
T_TYPE constantinteger:=109;
T_CLOB constantinteger:=112;
T_BLOB constantinteger:=113;
T_BFILE constantinteger:=114;
begin
ifnvl(p_max_rows,0)=0then
l_max_rows :=null;
else
l_max_rows := p_max_rows;
endif;
if p_current_exec =0then
selectvalueinto l_hold_date_format
from nls_session_parameters where parameter ='NLS_DATE_FORMAT';
executeimmediate'alter session set nls_date_format =
''DD-MON-YYYY HH24:MI''';
endif;
begin
v_cursor_id := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor_id, p_sql_statement, DBMS_SQL.V7);
DBMS_SQL.DESCRIBE_COLUMNS(v_cursor_id, column_high, v_describe);
hold_sql :='select ';
hold_sql_needed :=null;
hold_exclude_cols :=false;
hold_sql_remain :=ltrim(substr(replace(p_sql_statement,chr(10),' '),7));
for value_counter in1..column_high loop
if v_describe(value_counter).col_type = T_LONG then
hold_length :=25000;
else
hold_length :=to_number(v_describe(value_counter).col_max_len);
endif;
if v_describe(value_counter).col_type in(T_DATE, T_VARCHAR2,
T_NUMBER, T_CHAR, T_ROWID)then
DBMS_SQL.DEFINE_COLUMN(v_cursor_id, value_counter,
hold_string,greatest(hold_length,30));
elsif v_describe(value_counter).col_type = T_CLOB then
DBMS_SQL.DEFINE_COLUMN(v_cursor_id, value_counter, hold_clob);
else
null;
endif;
hold_string := v_describe(value_counter).col_name;
if value_counter =1then
v_values := V2T(replace(initcap(hold_string),'|','<br>'));
else
v_values.EXTEND;
v_values(value_counter):=replace(initcap(hold_string),'|','<br>');
endif;
ifsubstr(hold_sql_remain,1,1) !='*'then
hold_end_pos :=1;
hold_open_paren :=0;
loop
ifsubstr(hold_sql_remain,hold_end_pos,1)='('then
hold_open_paren := hold_open_paren +1;
elsifsubstr(hold_sql_remain,hold_end_pos,1)=')'then
hold_open_paren := hold_open_paren -1;
elsifsubstr(hold_sql_remain,hold_end_pos,1)=','or
lower(substr(hold_sql_remain, hold_end_pos,4))=' from 'then
if hold_open_paren =0then
exit;
endif;
endif;
hold_end_pos := hold_end_pos +1;
if hold_end_pos >length(p_sql_statement)then
exit;
endif;
endloop;
hold_element :=substr(hold_sql_remain,1, hold_end_pos);
hold_sql_remain :=ltrim(substr(hold_sql_remain, hold_end_pos +1));
else
hold_element := v_describe(value_counter).col_name;
endif;
if v_describe(value_counter).col_type in
(T_VARCHAR2, T_CHAR, T_NUMBER, T_DATE, T_LONG, T_CLOB, T_ROWID)then
hold_sql := hold_sql || hold_sql_needed || hold_element;
else
hold_exclude_cols :=true;
endif;
hold_sql_needed :=', ';
endloop;
if hold_exclude_cols then
DBMS_SQL.CLOSE_CURSOR(v_cursor_id);
hold_sql := hold_sql ||' '||
substr(p_sql_statement,instr(lower(p_sql_statement),' from '));
row_counter := Display_SQL (hold_sql, table_alias, display_longs,
p_feedback, p_max_rows, p_ind_level, p_current_exec +1)+1;
else
ifnvl(p_ind_level,0) !=0then
line_out('<div class=ind'||to_char(p_ind_level)||'>');
endif;
if table_alias isnotnullthen
line_out('<br><span class="BigPrint">'|| table_alias ||'</span>');
endif;
v_dummy := DBMS_SQL.EXECUTE(v_cursor_id);
row_counter :=1;
loop
if DBMS_SQL.FETCH_ROWS(v_cursor_id)=0then
exit;
endif;
if row_counter =1then
Start_Table(table_alias);
Show_Table_Header(v_values);
endif;
for value_counter in1..column_high loop
if v_describe(value_counter).col_type in
(T_DATE, T_VARCHAR2, T_NUMBER, T_CHAR, T_ROWID)then
DBMS_SQL.COLUMN_VALUE(v_cursor_id,value_counter,hold_string);
else
DBMS_SQL.COLUMN_VALUE(v_cursor_id,value_counter,hold_clob);
hold_string :='CLOB';
endif;
hold_string :=nvl(hold_string,' ');
hold_option :=null;
if v_describe(value_counter).col_type = T_DATE then
hold_string :=replace(hold_string,' ',' ');
hold_option :='nowrap align=right';
elsif v_describe(value_counter).col_type = T_VARCHAR2 then
hold_string :=replace(replace(hold_string,'<','<'),
'>','>');
hold_string :=replace(hold_string,chr(10),'<BR>');
if hold_string !=rtrim(hold_string)then
hold_option :='nowrap bgcolor=yellow';
else
hold_option :='nowrap';
endif;
elsif v_describe(value_counter).col_type = T_NUMBER then
hold_option :='nowrap align=right';
else
null;
endif;
if value_counter =1then
v_values := V2T(hold_string);
v_options := V2T(hold_option);
else
v_values.EXTEND;
v_values(value_counter):= hold_string;
v_options.EXTEND;
v_options(value_counter):= hold_option;
endif;
endloop;
Show_Table_Row(v_values, v_options);
row_counter := row_counter +1;
if row_counter > nvl(l_max_rows,row_counter)then
exit;
endif;
endloop;
DBMS_SQL.CLOSE_CURSOR(v_cursor_id);
End_Table;
ifnvl(p_ind_level,0) !=0then
line_out('</div>');
endif;
endif;
if p_current_exec =0and p_feedback ='Y'then
if row_counter =1then
l_feedback_txt :='<BR><span class="SmallPrint">'||
'0 Rows Selected</span><br>';
elsif row_counter =2then
l_feedback_txt :='<span class="SmallPrint">'||
'1 Row Selected</span><br>';
else
l_feedback_txt :='<span class="SmallPrint">'||
ltrim(to_char(row_counter -1,'9999999'))||
' Rows Selected</span><br>';
endif;
line_out(l_feedback_txt);
executeimmediate'alter session set nls_date_format = '''||
l_hold_date_format ||'''';
endif;
if p_current_exec =0and row_counter =1then
line_out('<BR>');
endif;
return row_counter-1;
exception
whenothersthen
line_out('</table><br>');
error_position := DBMS_SQL.LAST_ERROR_POSITION;
ErrorPrint(sqlerrm||' occurred in Display_SQL');
ActionErrorPrint('Please report the error below to your support '||
'representative');
line_out('Position: '|| error_position ||' of '||
length(p_sql_statement)||'<br>');
line_out(replace(substr(p_sql_statement,1,error_position),chr(10),
'<br>'));
error_position_end :=instr(p_sql_statement,' ',error_position+1)-
error_position;
line_out('<span class="error">'||
replace(substr(p_sql_statement,error_position+1,
error_position_end),chr(10),'<br>')||'</span>');
line_out(replace(substr(p_sql_statement,error_position+
error_position_end+1),chr(10),'<br>')||'<br>');
DBMS_SQL.CLOSE_CURSOR(v_cursor_id);
if p_current_exec =0then
executeimmediate'alter session set nls_date_format = '''||
l_hold_date_format ||'''';
endif;
return-1;
end;
end Display_SQL;
-- Function Name: Run_SQL
--
-- Usage:
-- a_number := Run_SQL('Heading', 'SQL statement');
-- a_number := Run_SQL('Heading', 'SQL statement', 'Feedback');
-- a_number := Run_SQL('Heading', 'SQL statement', 'Max Rows');
-- a_number := Run_SQL('Heading', 'SQL statement', 'Feedback', 'Max Rows');
-- a_number := Run_SQL('Heading', 'SQL statement', 'Feedback', 'Max Rows',
-- 'Indent Level');
--
-- Parameters:
-- Heading - Text String to for heading the output
-- SQL Statement - Any valid SQL Select Statement
-- Feedback - Y or N to indicate whether to automatically print the
-- number of rows returned (default 'Y')
-- Max Rows - Limit the output to this many rows. NULL or ZERO values
-- indicate unlimited rows (default NULL)
-- Indent Level - Indicate if table should be indented and by how much
-- 0=No indentation, 1=.25in, 2=.5in, 3=.75in (default 0)
--
-- Returns:
-- The function returns the # of rows selected.
-- If there is an error then the function returns -1.
--
-- Output:
-- Displays the output of the SQL statement as an HTML table.
--
-- Examples:
-- declare
-- num_rows number;
-- begin
-- num_rows := Run_SQL('AR Parameters',
-- 'select * from ar_system_parameters_all');
-- end;
--
function Run_SQL(p_title varchar2, p_sql_statement varchar2)returnnumberis
begin
return(Display_SQL(p_sql_statement , p_title ,'Y','Y',null));
end Run_SQL;
function Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_feedback varchar2)returnnumberis
begin
return(Display_SQL(p_sql_statement , p_title ,'Y',p_feedback,null,0));
end Run_SQL;
function Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_max_rows number)returnnumberis
begin
return(Display_SQL(p_sql_statement , p_title ,'Y','Y',p_max_rows,0));
end Run_SQL;
function Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_feedback varchar2
, p_max_rows number)returnnumberis
begin
return(Display_SQL(p_sql_statement , p_title ,'Y',p_feedback,p_max_rows,0));
end Run_SQL;
function Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_feedback varchar2
, p_max_rows number
, p_ind_level number)returnnumberis
begin
return(Display_SQL(p_sql_statement , p_title ,'Y',p_feedback,p_max_rows,
p_ind_level));
end Run_SQL;
-- Procedure Name: Run_SQL
--
-- Usage:
-- Run_SQL('Heading', 'SQL statement');
-- Run_SQL('Heading', 'SQL statement', 'Feedback');
-- Run_SQL('Heading', 'SQL statement', 'Max Rows');
-- Run_SQL('Heading', 'SQL statement', 'Feedback', 'Max Rows');
-- Run_SQL('Heading', 'SQL statement', 'Feedback', 'Max Rows',
-- 'Indent Level');
--
-- Parameters:
-- Heading - Text String to for heading the output
-- SQL Statement - Any valid SQL Select Statement
-- Feedback - Y or N to indicate whether to automatically print the
-- number of rows returned (default 'Y')
-- Max Rows - Limit the output to this many rows. NULL or ZERO values
-- indicate unlimited rows (default NULL)
-- Indent Level - Indicate if table should be indented and by how much
-- 0=No indentation, 1=.25in, 2=.5in, 3=.75in (default 0)
--
-- Output:
-- Displays the output of the SQL statement as an HTML table.
--
-- Examples:
-- begin
-- Run_SQL('AR Parameters', 'select * from ar_system_parameters_all');
-- end;
--
procedure Run_SQL(p_title varchar2, p_sql_statement varchar2)is
dummy number;
begin
dummy := Display_SQL (p_sql_statement , p_title ,'Y','Y',null,0);
end Run_SQL;
procedure Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_feedback varchar2)is
dummy number;
begin
dummy := Display_SQL (p_sql_statement , p_title ,'Y', p_feedback,null,0);
end Run_SQL;
procedure Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_max_rows number)is
dummy number;
begin
dummy := Display_SQL (p_sql_statement , p_title ,'Y','Y', p_max_rows,0);
end Run_SQL;
procedure Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_feedback varchar2
, p_max_rows number)is
dummy number;
begin
dummy := Display_SQL (p_sql_statement , p_title ,'Y',
p_feedback, p_max_rows,0);
end Run_SQL;
procedure Run_SQL(p_title varchar2
, p_sql_statement varchar2
, p_feedback varchar2
, p_max_rows number
, p_ind_level number)is
dummy number;
begin
dummy := Display_SQL (p_sql_statement , p_title ,'Y',
p_feedback, p_max_rows, p_ind_level);
end Run_SQL;
-- Procedure Name: Display_Table
--
-- Usage:
-- Display_Table('Table Name', 'Heading', 'Where Clause', 'Order By', 'Long Flag');
--
-- Parameters:
-- Table Name - Any Valid Table or View
-- Heading - Text String to for heading the output
-- Where Clause - Where clause to apply to the table dump
-- Order By - Order By clause to apply to the table dump
-- Long Flag - 'Y' or 'N' - If set to 'N' then this will not output any LONG columns
--
-- Output:
-- Displays the output of the 'select * from table' as an HTML table.
--
-- Examples:
-- begin
-- Display_Table('AR_SYSTEM_PARAMETERS_ALL', 'AR Parameters', 'Where Org_id != -3113'
-- , 'order by org_id, set_of_books_id', 'N');
-- end;
--
procedure Display_Table (p_table_name varchar2,
p_table_alias varchar2,
p_where_clause varchar2,
p_order_by_clause varchar2defaultnull,
p_display_longs varchar2default'Y')is
dummy number;
hold_char varchar(1):=null;
begin
if p_where_clause isnotnullthen
hold_char :=chr(10);
endif;
dummy := Display_SQL ('select * from '||
replace(upper(p_table_name),'V_$','V$')||chr(10)|| p_where_clause ||
hold_char ||nvl(p_order_by_clause,'order by 1')
,nvl(p_table_alias, p_table_name)
, p_display_longs);
end Display_Table;