0
create or replace procedure summery_report_date_range (start_date in varchar2 , end_date in varchar2 )
is
cursor cursor_audit is SELECT audit_action, COUNT(audit_action), audit_user, audit_date ,
TABLE_NAME
FROM (
select audit_action, audit_user, audit_date, 'store_audit' TABLE_NAME
from stores_audit
UNION ALL
select audit_action, audit_user, audit_date, 'customer_audit' TABLE_NAME
from customer_audit
UNION ALL
select audit_action, audit_user, audit_date, 'category_audit' TABLE_NAME
from category_audit
UNION ALL
select audit_action, audit_user, audit_date, 'orders_audit' TABLE_NAME
from orders_audit
)"MYTBL"
where (audit_date between TO_DATE(start_date, 'DD-MON-YY') and TO_DATE(end_date, 'DD-MON-YY') )
GROUP BY audit_action, audit_user, audit_date, TABLE_NAME
ORDER BY audit_user;
rec_user stores_audit.audit_user%TYPE;
rec_total number;
rec_action stores_audit.audit_action%TYPE;
rec_date stores_audit.audit_date%TYPE;
rec_id stores_audit.audit_id%TYPE;
begin
open cursor_audit;
fetch cursor_audit into rec_action, rec_total,rec_user,rec_date,rec_id ;
while cursor_audit%found
loop
dbms_output.put_line('User : '||rec_user ||', Action : ' ||
rec_action ||', Date From: ' ||start_date ||' To ' || END_DATE || ' Total Action : ' || rec_total);
fetch cursor_audit into rec_action, rec_total, rec_user,rec_date,rec_id ;
end loop;
close cursor_audit;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Data Not Found.');
WHEN INVALID_CURSOR THEN
DBMS_OUTPUT.PUT_LINE('INVALID_CURSOR.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM || ' ' ||SQLCODE);
end;
/
execute summery_report_date_range('01-DEC-10' , '31-DEC-10');
私は、正確なエラーORA-06502:PL/SQL:数値または値のエラー:番号変換エラーに文字
まず、 'DBMS_OUTPUT.PUT_LINE(SQLERRM || '|| SQLCODE);を' DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE) 'に置き換えてください。 - どのラインが問題を引き起こしているのかがわかるはずです。 – Sathya