Hi everybody,
I am trying to generate a report about the queries with the most disk reads. The generated report will be sent as email. I wrote some code as below. When i include top 15 query it works fine but if i increase hte count i get 'numeric or value error'. I guess this happens because i exceed some datatypes limit but could not identify it. Anybodyy is seeing the problem ? And how can i send huge report without an error like this?
I have a F_GENERATE_REPORT function and P_SEND_REPORT_AS_EMAIL procedure. P_SEND_REPORT_AS_EMAIL procedure uses F_GENERATE_REPORT as the body of the email like UTL_MAIL.SEND(message => F_GENERATE_REPORT(5)) where 5 used for tOP 5.
Error occures on the line UTL_MAIL.SEND() in the procedure P_SEND_REPORT_AS_EMAIL
Thanks all.
clgenerated_html_markup is an CLOB.
FOR cur_for_query IN (SELECT *
FROM (SELECT buffer_gets,rows_processed,executions,
fetches,hash_value,sql_text, disk_reads,
rank() over(ORDER BY disk_reads DESC) AS rank FROM v$sqlarea)
WHERE rank <= nquery_count)
LOOP
--dbms_output.put_line(counter);
--counter := counter + 1;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEROWOPEN || CHR(10) ;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA(cur_for_query.rank,null,null,null,null,null,'class=tdData') || CHR(10) ;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA(cur_for_query.sql_text,null,null,null,null,null,'class=tdSQLText') || CHR(10) ;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA(TO_CHAR(NVL(cur_for_query.disk_reads,'')),'CENTER',null,null,null,null,'class=tdData') || CHR(10) ;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA(TO_CHAR(NVL(cur_for_query.buffer_gets,'')),'CENTER',null,null,null,null,'class=tdData') || CHR(10) ;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA(TO_CHAR(NVL(cur_for_query.executions,'')),'CENTER',null,null,null,null,'class=tdData') || CHR(10) ;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA(TO_CHAR(NVL(cur_for_query.fetches,'')),'CENTER',null,null,null,null,'class=tdData') || CHR(10) ;
--clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA('','CENTER',null,null,null,null,'class=tdData') || CHR(10) ;
--clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEDATA('','CENTER',null,null,null,null,'class=tdData') || CHR(10) ;
clgenerated_html_markup := clgenerated_html_markup || HTF.TABLEROWCLOSE || CHR(10) ;
END LOOP;
Send Email Procedure
PROCEDURE P_SEND_REPORT_AS_EMAIL
(
vreceipent VARCHAR2,
vsubject VARCHAR2,
nquery_count NUMBER DEFAULT 5
)
IS
BEGIN
-- INPUT VALIDATION
IF vreceipent IS NULL THEN
RAISE_APPLICATION_ERROR(value_can_not_be_null,'DBA_EXHAUSTIVE_QUERY_PKG::P_SEND_REPORT_AS_EMAIL::Receipent Email Address Can Not Be Null.');
END IF;
-- END OF INPUT VALIDATION
UTL_MAIL.SEND(sender => '[email protected]',
recipients => vreceipent,
subject => NVL(vsubject,''),
message => F_GENERATE_REPORT(nquery_count),
mime_type => 'text/html; charset=us-ascii');
EXCEPTION
WHEN OTHERS THEN
-- TODO LOG ERROR HERE
RAISE;
END P_SEND_REPORT_AS_EMAIL;