DBMS_UTILITY.FORMAT_CALL_STACK
Hi All,
Could you one tell me when i am running DBMS_UTILITY.FORMAT_CALL_STACK, i am getting one environment 11 alpha numeric character(0x3a135c3a8) for object handle and in another environment is giving 16 alpha numeric character(00000007A6B3ED30) for object handle.
One Enviroment:
begin
dbms_output.put_line(DBMS_UTILITY.FORMAT_CALL_STACK);
end;
----- PL/SQL Call Stack -----
object line object
handle number name
0x3a135c3a8 2 anonymous block
Another Enviroment:
----- PL/SQL Call Stack -----
object line object
handle number name
00000007A6B3ED30 2 anonymous block
Could any one explain why the difference.
Thanks
11gR2 is not a version number; it is a marketing label. 11.2.0.3 is a proper version number.
Are both environments the same bitmode? Are both Oracle environments housed on the same OS version?
What difference does it make if the handle length is different since the basic format of the data returned is the same? Are you trying to parse the call stack? If so, your logic should not depend on fixed lengths but should locate value beginning and ending value locations.
HTH -- Mark D Powell --
Similar Messages
-
Any alternatives for dbms_utility.format_call_stack?
For the freaks out there:
isn't there an alternative for dbms_utility.format_call_stack, since this will not work in server-side pl/sql when called from Oracle Forms. I'm searching something like a Data Dictionary View where I can retrieve this kind of information.
Regards, RoelI am having the same problem.
I need a way to trace the path, even when the code is called from Forms.
Any ideas?? -
Hi,
If I call procedure through DB_LINK, FORMAT_CALL_STACK return nothing.
Can I somehow to define the name of procedure, that call me?I am having the same problem.
I need a way to trace the path, even when the code is called from Forms.
Any ideas?? -
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE in 9i
Hello,
I have a procedure that calls a lot of procedures, functions, packages in 9i database.
I'm trying to send an email with the error information whenever an error prevents the procedure to execute with success.
I searched something about this and i'm using this code for trapping the possible error:
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR');
DBMS_OUTPUT.PUT_LINE ('error code ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE ('error MESSAGE ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE ('ERROR STACK:' ||DBMS_UTILITY.FORMAT_ERROR_STACK);
END;
But in this information is missing the exactly program (function, procedure or package) and line number.
I could do this using
DBMS_OUTPUT.PUT_LINE ('ERROR BACKTRACE:' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
But i think is not available on database 9i.
How can i get this kind of result in database 9i?
Thank you.
RuteHello,
the DBMS_UTILITY.FORMAT_CALL_STACK gives me:
ERROR STACK:ORA-01407: cannot update ("DVA2"."P1ALLA"."CFASTC") to NULL
ERROR STACK:----- PL/SQL Call Stack -----
object line object
handle number
name
66D1BDD4 453 procedure DVA2.P1053FCLNV
655EEB28 2 anonymous block
That gives me the error "ORA-01407: cannot update ("DVA2"."P1ALLA"."CFASTC") to NULL", gives the name and line in the principal procedure "453 procedure DVA2.P1053FCLNV" but it does not give the name of the package where the error ocurred!
There is anything else?
Thank you. -
FORMAT_CALL_STACK
Hi all,
can anybody help me to extract procedure name outof DBMS_UTILITY.FORMAT_CALL_STACK . ?
thanx in advance.Perhaps, technical problem leads op to this disaster. I mean to say three duplicate post. ;)
Regards.
Satyaki De. -
How to get value and name of the n'th parameter in a pl/sql funct./proced.
procedure test(name varchar2, birthdate date, zip number, country varchar2);
in procedure x I do
test('Michael Postmann', to_date('03.01.1983', 'DD.MM.YYYY'), 7461, 'AUSTRIA');
And this should htp.print the following:
test: name=Michael Postmann,birthdate=1983/01/03,zip=7461,country=AUSTRIA
In procedure test I want to know:
*) What is the name of myself (the procedure)
*) Optionally: Am I a procedure or a function?
*) How many Parameters do I have?
*) What are the values of them?
*) What are the names of them?
*) Optionally: What are the types of them?
What I actually want to do is:
I have a procedure for logging errors. So in my program I call this function frequently and I want it to log the current time, a string passed to the logging function, the client's ip, etc.... but it should also log a list of the parametrs and values of the procedure/function where the error occoured.
Is there any way to do this (I think in C this is done by argc and argv, but a string containing all the information (as you get it from the WebDb when something goes wrong) would be enough)?
Thx in advance,
Nomike aka Michael PostmannName of procedure or function can be retrieved using DBMS_UTILITY.FORMAT_CALL_STACK:
CREATE OR REPLACE FUNCTION fn_whoami (v_in varchar2)
RETURN varchar2
AS
v_stack varchar2(1000) DEFAULT DBMS_UTILITY.FORMAT_CALL_STACK;
v_job varchar2(500);
v_name varchar2(100);
BEGIN
v_job := SUBSTR(v_stack,INSTR(v_stack,'function'),256);
v_name := SUBSTR(v_job,1,INSTR(v_job,CHR(10))-1);
return v_name;
END fn_whoami;
select fn_whoami('1') from dual;
CREATE OR REPLACE PROCEDURE pr_whoami
AS
v_stack varchar2(1000) DEFAULT DBMS_UTILITY.FORMAT_CALL_STACK;
v_job varchar2(500);
v_name varchar2(100);
BEGIN
v_job := SUBSTR(v_stack,INSTR(v_stack,'procedure'),256);
v_name := SUBSTR(v_job,1,INSTR(v_job,CHR(10))-1);
dbms_output.put_line(v_name);
END pr_whoami;
exec pr_whoami; -
How to find out which job is calling package
Respected sir,
How to find out which job is calling my package. Please help me regarding this.
Regards,
user570124Please read about [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_util.htm#i997163]DBMS_UTILITY.FORMAT_CALL_STACK in the manual.
or [url http://asktom.oracle.com/tkyte/who_called_me/index.html]this routine from Tom Kyte may be what you are looking for.
Regards,
Rob. -
Mail needs to be sent after updating the salary column of emp table
Hi,
we have table test_emp_table, oracle form based application is running on this table...
it conatins salary column, we have requirement that, when every any update to the salary column, a mail needs to be sent to concerned person with new and old salary values..
I did that using the following procedure...
===========
-- Create Temporary Table to hold the Updated values
create table email_parameters
( id number primary key,
oldsal varchar2(10),
newsal varchar2(10),
ename varchar2(100));
--- Create Procedure
CREATE OR REPLACE PROCEDURE send_email_new (
l_job IN NUMBER ) is
l_oldsal varchar2(100);
l_newsal varchar2(100);
l_emp_name varchar2(100);
l_message varchar2(100);
BEGIN
SELECT oldsal
INTO l_oldsal
FROM email_parameters
WHERE ID = l_job;
SELECT newsal
INTO l_newsal
FROM email_parameters
WHERE ID = l_job;
SELECT ename
INTO l_emp_name
FROM email_parameters
WHERE ID = l_job;
l_message:=
'Employee Name= '
|| l_emp_name
|| chr(10)||chr(10)
|| 'Old Salary= '
|| l_oldsal
|| chr(10)||chr(10)
|| 'New Salary= '
|| l_newsal;
send_mail(l_message);
DELETE FROM email_parameters
WHERE ID = l_job;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_call_stack);
END;
--- Create Trigger
create or replace trigger send_email_trg
after update on TEST_EMP_TABLE
for each row
declare
l_job number;
begin
dbms_job.submit (job => l_job,
what => 'send_email_new(job);' );
insert into email_parameters
values (l_job, :old.sal,:new.sal,:new.ename);
end send_email_trg;
-- Create Procedure for Sending Mail
create or replace procedure send_mail(l_message varchar2) is
c utl_smtp.connection;
PROCEDURE send_header(name VARCHAR2, header VARCHAR2) AS
BEGIN
utl_smtp.write_data(c,name ||':'|| header || UTL_TCP.CRLF);
END;
BEGIN
c := utl_smtp.open_connection('192.168.0.18');
utl_smtp.helo(c, 'abc.com');
utl_smtp.mail(c, '[email protected]');
utl_smtp.rcpt(c, '[email protected]');
utl_smtp.open_data(c);
send_header('From', '[email protected]');
send_header('To', '[email protected]');
send_header('Subject', 'Warning: Employee Solary has been updated!');
utl_smtp.write_data(c, UTL_TCP.CRLF || l_message);
utl_smtp.close_data(c);
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error
OR utl_smtp.permanent_error THEN
NULL;
END;
raise_application_error(-20000, SQLERRM);
END;
====================
But I have doubt, if there is any problem with mail server, if user is updating salary column from form based application at same time....
will table trigger allows him to save the new record or not????? or will he get any errors????thanks justin...
I have written that code..but it works...problem is ...i am not able to understand the flow...what happens in the order, until mail is sent...
i have another code.....
I have written with out dbms_job, i have witten directly in the trigger itself...
Tom suggested the procedure, what i have given above..but not the below procedure....
I am not able to understand, what is the difference between them.....
CREATE OR REPLACE TRIGGER test_emp_table_trg
AFTER UPDATE
ON test_emp_table
FOR EACH ROW
WHEN (NEW.sal <> OLD.sal)
DECLARE
l_employee_name VARCHAR2 (240);
l_old_sal VARCHAR2 (240);
l_new_sal VARCHAR2 (240);
l_message VARCHAR2 (240);
BEGIN
/* Gets the employee full name */
BEGIN
SELECT ename
INTO l_employee_name
FROM test_emp_table
WHERE empno = :OLD.empno;
EXCEPTION
WHEN OTHERS
THEN
l_employee_name := NULL;
END;
/* Gets the old Salary */
BEGIN
SELECT sal
INTO l_old_sal
FROM test_emp_table
WHERE empno = :OLD.empno;
EXCEPTION
WHEN OTHERS
THEN
l_old_sal := 0;
END;
/* Gets the new position name */
BEGIN
SELECT sal
INTO l_new_sal
FROM test_emp_table
WHERE empno= :NEW.empno;
EXCEPTION
WHEN OTHERS
THEN
l_new_sal := 0;
END;
l_message:=
'Employee Name= '
|| l_employee_name
|| 'Old Salary= '
|| l_old_sal
|| 'New Salary= '
|| l_new_sal;
BEGIN
send_mail (l_message);
END;
==========
can you please describe it clearly???
thanks in advance my dear friend????
Edited by: oraDBA2 on Oct 4, 2008 10:26 PM -
How to get the current schema name
Hi,
Can anybody please tell me how to get the current schema name, there is some inbuilt function for this,but i am not getting that. Please help me.
Thanks
Jogeshok folks, I found the answer at Tom's as usual.
http://asktom.oracle.com/tkyte/who_called_me/index.html
I rewrote it into a function for kicks. just pass the results of DBMS_UTILITY.FORMAT_CALL_STACK to this function and you will get back the owner of the code making the call as well some extra goodies like the name of the code and the type of code depending on the parameter. This ignores the AUTHID CURRENT_USER issues which muddles the schemaid. Quick question, does the average user always have access to DBMS_UTILITY.FORMAT_CALL_STACK or does this get locked down on some systems?
cheers,
paul
create or replace
FUNCTION SELF_EXAM (
p_call_stack VARCHAR2,
p_type VARCHAR2 DEFAULT 'SCHEMA'
) RETURN VARCHAR2
AS
str_stack VARCHAR2(4000);
int_n PLS_INTEGER;
str_line VARCHAR2(255);
found_stack BOOLEAN DEFAULT FALSE;
int_cnt PLS_INTEGER := 0;
str_caller VARCHAR2(30);
str_name VARCHAR2(30);
str_owner VARCHAR2(30);
str_type VARCHAR2(30);
BEGIN
str_stack := p_call_stack;
-- Loop through each line of the call stack
LOOP
int_n := INSTR( str_stack, chr(10) );
EXIT WHEN int_cnt = 3 OR int_n IS NULL OR int_n = 0;
-- get the line
str_line := SUBSTR( str_stack, 1, int_n - 1 );
-- remove the line from the stack str
str_stack := substr( str_stack, int_n + 1 );
IF NOT found_stack
THEN
IF str_line like '%handle%number%name%'
THEN
found_stack := TRUE;
END IF;
ELSE
int_cnt := int_cnt + 1;
-- cnt = 1 is ME
-- cnt = 2 is MY Caller
-- cnt = 3 is Their Caller
IF int_cnt = 1
THEN
str_line := SUBSTR( str_line, 22 );
dbms_output.put_line('->' || str_line);
IF str_line LIKE 'pr%'
THEN
int_n := LENGTH('procedure ');
ELSIF str_line LIKE 'fun%'
THEN
int_n := LENGTH('function ');
ELSIF str_line LIKE 'package body%'
THEN
int_n := LENGTH('package body ');
ELSIF str_line LIKE 'pack%'
THEN
int_n := LENGTH('package ');
ELSIF str_line LIKE 'anonymous%'
THEN
int_n := LENGTH('anonymous block ');
ELSE
int_n := null;
END IF;
IF int_n IS NOT NULL
THEN
str_type := LTRIM(RTRIM(UPPER(SUBSTR( str_line, 1, int_n - 1 ))));
ELSE
str_type := 'TRIGGER';
END IF;
str_line := SUBSTR( str_line, NVL(int_n,1) );
int_n := INSTR( str_line, '.' );
str_owner := LTRIM(RTRIM(SUBSTR( str_line, 1, int_n - 1 )));
str_name := LTRIM(RTRIM(SUBSTR( str_line, int_n + 1 )));
END IF;
END IF;
END LOOP;
IF UPPER(p_type) = 'NAME'
THEN
RETURN str_name;
ELSIF UPPER(p_type) = 'SCHEMA.NAME'
OR UPPER(p_type) = 'OWNER.NAME'
THEN
RETURN str_owner || '.' || str_name;
ELSIF UPPER(p_type) = 'TYPE'
THEN
RETURN str_type;
ELSE
RETURN str_owner;
END IF;
END SELF_EXAM; -
How to find out what code called the procedure
Hi,
I'm doing an error logging api, that will log errors when it's called. What I wasn't to know is if there's a way to find out what procedure/function called the api?
One way is to pass the function as a text variable but it would be cool if the api could find out who called it.
Hope i made myself clear :-)I think you can use DBMS_UTILITY.FORMAT_CALL_STACK (I assume that's also what Tom K is using in his utility - with a nice wrapper around it).
Look at this example:
SQL>CREATE OR REPLACE procedure p as
2 begin
3 dbms_output.put_line(dbms_utility.format_call_stack);
4 end;
5 /
Procedure created.
SQL>CREATE OR REPLACE procedure p2 as
2 begin
3 p;
4 end;
5 /
Procedure created.
SQL>CREATE OR REPLACE procedure p3 as
2 begin
3 p2;
4 end;
5 /
Procedure created.
SQL>exec p3;
----- PL/SQL Call Stack -----
object line object
handle number name
38aad05a8 3 procedure HRM.P
38aaa6990 3 procedure HRM.P2
38aa9f470 3 procedure HRM.P3
38a6e9d88 1 anonymous block
PL/SQL procedure successfully completed.
SQL> -
Hello to everyone.
Does somebody know how i can get the stored procedure which is
inserting or updating a table? I have many procedures inserting
rows in a table, and i want to identify which of them is adding
records.
I hope somebody can help me.
Thanks a lot.
Hazael Dorantes.
System AnalistSQL> CREATE TABLE audit_table
2 (table_name VARCHAR2 (30),
3 owner_name VARCHAR2 (30),
4 procedure_name VARCHAR2 (30))
5 /
Table created.
SQL> CREATE OR REPLACE TRIGGER insert_dept_trig
2 AFTER INSERT ON dept
3 DECLARE
4 v_owner_name VARCHAR2 (30) := NULL;
5 v_procedure_name VARCHAR2 (30) := NULL;
6 v_call_stack VARCHAR2 (4096) := NULL;
7 BEGIN
8 IF INSTR (DBMS_UTILITY.FORMAT_CALL_STACK, 'procedure') > 0
9 THEN
10 v_call_stack :=
11 SUBSTR (DBMS_UTILITY.FORMAT_CALL_STACK,
12 INSTR (DBMS_UTILITY.FORMAT_CALL_STACK,
13 'procedure') + 10);
14 v_owner_name :=
15 SUBSTR (v_call_stack, 1,
16 INSTR (v_call_stack, '.') - 1);
17 v_procedure_name :=
18 SUBSTR (v_call_stack,
19 INSTR (v_call_stack, '.') + 1, 30);
20 v_procedure_name :=
21 SUBSTR (v_procedure_name, 1,
22 INSTR (v_procedure_name, ' '));
23 END IF;
24 INSERT INTO audit_table
25 (table_name,
26 owner_name,
27 procedure_name)
28 VALUES
29 ('DEPT',
30 v_owner_name,
31 v_procedure_name);
32 END insert_dept_trig;
33 /
Trigger created.
SQL> CREATE OR REPLACE PROCEDURE insert_dept
2 AS
3 BEGIN
4 INSERT INTO dept (deptno)
5 VALUES (50);
6 END insert_dept;
7 /
Procedure created.
SQL> EXEC insert_dept
PL/SQL procedure successfully completed.
SQL> COLUMN table_name FORMAT A15 WORD_WRAPPED
SQL> COLUMN owner_name FORMAT A15 WORD_WRAPPED
SQL> COLUMN procedure_name FORMAT A15 WORD_WRAPPED
SQL> SELECT *
2 FROM audit_table
3 /
TABLE_NAME OWNER_NAME PROCEDURE_NAME
DEPT SCOTT INSERT_DEPT -
How to get block name in a tab canvas
I am trying to develope a form with six tabs on a tab canvas. Each tab pages contains a block derived from a database table and not items taken from the same table.
If I want to capture the name of the block in a tab page when page is changed, How can I do it.If you like CRAZY PAIN you can parse dbms_utility.format_call_stack to get the trigger name and owner and then using all/user_triggers extract info of table name, which has such trigger defined on it.
Although I wouldn't do that :)
I'd simply create a variable in trigger definition containing table_name and/or another variable containing trigger name and use them.
It is especially easy if you are generating triggers for example for some auditing purposes.
Gints Plivna
http://www.gplivna.eu -
Hello,
i would like to know if there is any possibility in PL/SQL to get the current stack depth inoformation. I am not sure if this is the right description, i would like to know how deep into calling subprograms has a program execution come at the moment.
I would like to use this information for automatical indentation of log file, produced by a pl/sql procedure call.948452 wrote:
Can you please provide me with some sample code?Unable to read the documentation for some reason?
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure callme(x in number, y in number) is
2 v_call_stack varchar2(32767);
3 begin
4 v_call_stack := dbms_utility.format_call_stack();
5 dbms_output.put_line(v_call_stack);
6 if x < y then
7 callme(x+1,y);
8 end if;
9* end;
SQL> /
Procedure created.
SQL> exec callme(1,5);
----- PL/SQL Call Stack -----
object line object
handle number name
3F6E5040 4 procedure SCOTT.CALLME
482416A0 1 anonymous block
----- PL/SQL Call Stack -----
object line object
handle number name
3F6E5040 4 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
482416A0 1 anonymous block
----- PL/SQL Call Stack -----
object line object
handle number name
3F6E5040 4 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
482416A0 1 anonymous block
----- PL/SQL Call Stack -----
object line object
handle number name
3F6E5040 4 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
3F6E5040 7 procedure
SCOTT.CALLME
482416A0 1 anonymous block
----- PL/SQL Call Stack -----
object line object
handle number name
3F6E5040 4 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
3F6E5040 7 procedure SCOTT.CALLME
482416A0 1 anonymous block
PL/SQL procedure successfully completed. -
How to find package name of transactioncode
hai friends,
how i can find the package name for a given transaction code .
i think by using se93
Moderator message: please search for available information.
Edited by: Thomas Zloch on Jul 8, 2011 9:52 AMNot sure, if this is what you're looking for
SQL> create or replace procedure p0 as
2 begin
3 dbms_output.put_line(dbms_utility.format_call_stack);
4 end;
5 /
Procedure created.
SQL> create or replace procedure p1 as
2 begin
3 p0;
4 end;
5 /
Procedure created.
SQL> create or replace procedure p2 as
2 begin
3 p1;
4 end;
5 /
Procedure created.
SQL> set serveroutput on
SQL> begin
2 p2;
3 end;
4 /
----- PL/SQL Call Stack -----
object line object
handle number name
3a7f2d618 3 procedure INV_ADM.P0
39abfeef0 3 procedure INV_ADM.P1
39c5ae7a0 3 procedure INV_ADM.P2
3a0f3a538 2 anonymous block
PL/SQL procedure successfully completed.
SQL> -
How to send e-mail with an attachment from remote database server.???
Hi All,
I have tried the simple mail sending and with the attachment using UTL_SMTP. But the problem is , it is sending the mail with attachment of the file name i give, it takes and creates that file and sends as attachment not from the actual file location. I am trying to attach the file which i stored in remote database server.
The following code I tried. But not worked for attachment
DECLARE
v_From VARCHAR2(80) := '[email protected]';
v_Recipient VARCHAR2(80) := '[email protected]';
v_Subject VARCHAR2(80) := 'test subject';
v_Mail_Host VARCHAR2(30) := 'pop3.somedomain.com';
v_Mail_Conn utl_smtp.Connection;
crlf VARCHAR2(2) := chr(13)||chr(10);
BEGIN
v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
utl_smtp.Mail(v_Mail_Conn, v_From);
utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
utl_smtp.Data(v_Mail_Conn,
'Date: ' || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
'From: ' || v_From || crlf ||
'Subject: '|| v_Subject || crlf ||
'To: ' || v_Recipient || crlf ||
'MIME-Version: 1.0'|| crlf || -- Use MIME mail standard
'Content-Type: multipart/mixed;'|| crlf ||
' boundary="-----SECBOUND"'|| crlf ||
crlf ||
'-------SECBOUND'|| crlf ||
'Content-Type: text/html;'|| crlf ||
'Content-Transfer_Encoding: 7bit'|| crlf ||
crlf ||
'some message text'|| crlf || -- Message body
'more message text'|| crlf ||
crlf ||
'-------SECBOUND'|| crlf ||
'Content-Type: text/html;'|| crlf ||
' name="Fund Authorization report"'|| crlf ||
'Content-Transfer_Encoding: 8bit'|| crlf ||
'Content-Disposition: attachment;'|| crlf ||
' filename="/usr/tmp/Test.html"'|| crlf ||
crlf ||
'HTML Attachment'|| crlf || -- Content of attachment
crlf ||
'-------SECBOUND--' -- End MIME mail
utl_smtp.Quit(v_mail_conn);
EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
END;How can I attach a file which is stored in database server and send it in a mail.
Please someone help me in this.
Thanks,
Alaka.Try this code
Regards Salim.
CREATE OR REPLACE TRIGGER EmailOnServerErr AFTER SERVERERROR ON DATABASE
DECLARE
mail_conn UTL_SMTP.connection;
crlf VARCHAR2(2) := chr(13)||chr(10);
msg VARCHAR2(32760);
sid_name VARCHAR2(16);
bdump_dest VARCHAR2(128);
smtp_relay VARCHAR2(32) := 'MyMailRelay';
recipient_address VARCHAR2(64) := '[email protected]';
sender_address VARCHAR2(64) := '[email protected]';
mail_port NUMBER := 25;
log_file_handle UTL_FILE.FILE_TYPE;
log_file_dir VARCHAR2(256) := 'ERR_LOG_DIR';
log_file_name VARCHAR2(256) := 'OracleErrors.log';
maxlinesize NUMBER := 32767;
session_rec sys.v_$session%ROWTYPE;
audit_rec sys.dba_audit_trail%ROWTYPE;
auditing BOOLEAN;
LinesOfSQL BINARY_INTEGER;
offending_sql DBMS_STANDARD.ora_name_list_t;
CURSOR bdump_cur IS
SELECT TRIM(value)
FROM v$parameter
WHERE name = 'background_dump_dest'
CURSOR sid_cur IS
SELECT TRIM(instance_name)
FROM v$instance
CURSOR session_cur IS
SELECT s.*
FROM v$session s
WHERE s.sid = dbms_support.mysid
CURSOR audit_trail_cur(AUDSID IN NUMBER) IS
SELECT *
FROM dba_audit_trail
WHERE sessionid = AUDSID
BEGIN
IF (USER = 'SYSTEM' OR USER = 'SYS') THEN
-- Ignore this error
NULL;
ELSIF IS_SERVERERROR (1034) THEN
-- Ignore this error
NULL;
ELSE
-- get the sid
OPEN sid_cur;
FETCH sid_cur INTO sid_name;
CLOSE sid_cur;
-- get the location of the alert log
OPEN bdump_cur;
FETCH bdump_cur INTO bdump_dest;
CLOSE bdump_cur;
-- get the session information
OPEN session_cur;
FETCH session_cur INTO session_rec;
CLOSE session_cur;
-- get the audit_trail information if it exists
OPEN audit_trail_cur(session_rec.audsid);
FETCH audit_trail_cur INTO audit_rec;
auditing := audit_trail_cur%FOUND;
CLOSE audit_trail_cur;
IF session_rec.program = 'MyProgram.exe' THEN
NULL; -- ignore actions from MyProgram - that's where I do maintenance
ELSE
-- compose the message
msg := 'Subject: Oracle error '||' on '||sid_name||crlf;
msg := msg||'To: '||recipient_address||crlf;
msg := msg||'For more information see the alert log file located at:'||crlf;
msg := msg||bdump_dest||'/alert_'||sid_name||'.log'||crlf;
msg := msg||'or the error log file: $'||log_file_dir||'/'||log_file_name||crlf;
msg := msg||'Error Time='||TO_CHAR(SYSDATE,'DD-Mon-YYYY HH24:MI:SS')||crlf;
msg := msg||DBMS_UTILITY.FORMAT_CALL_STACK||crlf;
LinesOfSQL := sql_txt(offending_sql);
msg := msg||'Offending SQL is:'||crlf;
FOR loop_counter IN offending_sql.FIRST..offending_sql.LAST
LOOP
msg := msg||offending_sql(loop_counter);
END LOOP;
msg := msg||crlf||'----- PL/SQL Error Stack -----'||crlf;
msg := msg||DBMS_UTILITY.FORMAT_ERROR_STACK||crlf;
msg := msg||'V$SESSION.SADDR=' ||session_rec.saddr ||crlf;
msg := msg||'V$SESSION.SID=' ||session_rec.sid ||crlf;
msg := msg||'V$SESSION.SERIAL#=' ||session_rec.serial# ||crlf;
msg := msg||'V$SESSION.AUDSID=' ||session_rec.audsid ||crlf;
msg := msg||'V$SESSION.PADDR=' ||session_rec.paddr ||crlf;
msg := msg||'V$SESSION.USER#=' ||session_rec.user# ||crlf;
msg := msg||'V$SESSION.USERNAME='||session_rec.username||crlf;
msg := msg||'V$SESSION.COMMAND=' ||session_rec.command ||crlf;
msg := msg||'V$SESSION.OWNERID=' ||session_rec.ownerid ||crlf;
msg := msg||'V$SESSION.TADDR=' ||NVL(session_rec.taddr ,'Null')||crlf;
msg := msg||'V$SESSION.LOCKWAIT='||NVL(session_rec.lockwait,'Null')||crlf;
msg := msg||'V$SESSION.STATUS=' ||NVL(session_rec.status ,'Null')||crlf;
msg := msg||'V$SESSION.SERVER=' ||NVL(session_rec.server ,'Null')||crlf;
msg := msg||'V$SESSION.SCHEMA#=' ||session_rec.schema#||crlf;
msg := msg||'V$SESSION.SCHEMANAME=' ||NVL(session_rec.schemaname,'Null')||crlf;
msg := msg||'V$SESSION.OSUSER=' ||NVL(session_rec.osuser ,'Null')||crlf;
msg := msg||'V$SESSION.PROCESS=' ||NVL(session_rec.process ,'Null')||crlf;
msg := msg||'V$SESSION.MACHINE=' ||NVL(session_rec.machine ,'Null')||crlf;
msg := msg||'V$SESSION.TERMINAL=' ||NVL(session_rec.terminal ,'Null')||crlf;
msg := msg||'V$SESSION.PROGRAM=' ||NVL(session_rec.program ,'Null')||crlf;
msg := msg||'V$SESSION.TYPE=' ||NVL(session_rec.type ,'Null')||crlf;
msg := msg||'V$SESSION.SQL_ADDRESS=' ||session_rec.sql_address ||crlf;
msg := msg||'V$SESSION.SQL_HASH_VALUE=' ||NVL(TO_CHAR(session_rec.sql_hash_value) ,'Null')||crlf;
msg := msg||'V$SESSION.PREV_SQL_ADDR=' ||session_rec.prev_sql_addr||crlf;
msg := msg||'V$SESSION.PREV_HASH_VALUE='||NVL(TO_CHAR(session_rec.prev_hash_value),'Null')||crlf;
msg := msg||'V$SESSION.MODULE=' ||NVL(session_rec.module ,'Null')||crlf;
msg := msg||'V$SESSION.MODULE_HASH='||NVL(TO_CHAR(session_rec.module_hash),'Null')||crlf;
msg := msg||'V$SESSION.ACTION=' ||NVL(session_rec.action ,'Null')||crlf;
msg := msg||'V$SESSION.ACTION_HASH='||NVL(TO_CHAR(session_rec.action_hash),'Null')||crlf;
msg := msg||'V$SESSION.CLIENT_INFO='||NVL(session_rec.client_info ,'Null')||crlf;
msg := msg||'V$SESSION.FIXED_TABLE_SEQUENCE='||NVL(TO_CHAR(session_rec.fixed_table_sequence),'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_OBJ#=' ||NVL(TO_CHAR(session_rec.row_wait_obj#) ,'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_FILE#=' ||NVL(TO_CHAR(session_rec.row_wait_file#) ,'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_BLOCK#='||NVL(TO_CHAR(session_rec.row_wait_block#),'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_ROW#=' ||NVL(TO_CHAR(session_rec.row_wait_row#) ,'Null')||crlf;
msg := msg||'V$SESSION.LOGON_TIME=' ||NVL(TO_CHAR(session_rec.logon_time,'DD-Mon-YYYY HH24:MI:SS'),'Null')||crlf;
msg := msg||'V$SESSION.LAST_CALL_ET=' ||NVL(TO_CHAR(session_rec.last_call_et) ,'Null')||crlf;
msg := msg||'V$SESSION.PDML_ENABLED=' ||NVL(session_rec.pdml_enabled ,'Null')||crlf;
msg := msg||'V$SESSION.FAILOVER_TYPE=' ||NVL(session_rec.failover_type ,'Null')||crlf;
msg := msg||'V$SESSION.FAILOVER_METHOD='||NVL(session_rec.failover_method,'Null')||crlf;
msg := msg||'V$SESSION.FAILED_OVER=' ||NVL(session_rec.failed_over ,'Null')||crlf;
msg := msg||'V$SESSION.RESOURCE_CONSUMER_GROUP='||NVL(session_rec.resource_consumer_group,'Null')||crlf;
msg := msg||'V$SESSION.PDML_STATUS=' ||NVL(session_rec.pdml_status ,'Null')||crlf;
msg := msg||'V$SESSION.PDDL_STATUS=' ||NVL(session_rec.pddl_status ,'Null')||crlf;
msg := msg||'V$SESSION.PQ_STATUS=' ||NVL(session_rec.pq_status ,'Null')||crlf;
IF auditing THEN
msg := msg||'DBA_AUDIT_TRAIL.OS_USERNAME=' ||NVL(audit_rec.os_username,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.USERNAME=' ||NVL(audit_rec.username ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.USERHOST=' ||NVL(audit_rec.userhost ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.TERMINAL=' ||NVL(audit_rec.terminal ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.TIMESTAMP=' ||TO_CHAR(audit_rec.timestamp,'DD-Mon-YYYY HH24:MI:SS')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.OWNER=' ||NVL(audit_rec.owner ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.OBJ_NAME=' ||NVL(audit_rec.obj_name ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ACTION=' ||audit_rec.action ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ACTION_NAME=' ||NVL(audit_rec.action_name ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.NEW_OWNER=' ||NVL(audit_rec.new_owner ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.NEW_NAME=' ||NVL(audit_rec.new_name ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.OBJ_PRIVILEGE='||NVL(audit_rec.obj_privilege ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.SYS_PRIVILEGE='||NVL(audit_rec.sys_privilege ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ADMIN_OPTION=' ||NVL(audit_rec.admin_option ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.GRANTEE=' ||NVL(audit_rec.grantee ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.AUDIT_OPTION=' ||NVL(audit_rec.audit_option ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.SES_ACTIONS=' ||NVL(audit_rec.ses_actions ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_TIME=' ||NVL(TO_CHAR(audit_rec.logoff_time) ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_LREAD=' ||NVL(TO_CHAR(audit_rec.logoff_lread) ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_PREAD=' ||NVL(TO_CHAR(audit_rec.logoff_pread) ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_LWRITE='||NVL(TO_CHAR(audit_rec.logoff_lwrite),'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_DLOCK=' ||NVL(audit_rec.logoff_dlock ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.COMMENT_TEXT=' ||NVL(audit_rec.comment_text ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.SESSIONID=' ||audit_rec.sessionid ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ENTRYID=' ||audit_rec.entryid ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.STATEMENTID=' ||audit_rec.statementid ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.RETURNCODE=' ||audit_rec.returncode ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.PRIV_USED=' ||NVL(audit_rec.priv_used,'Null')||crlf;
END IF;
msg := msg||'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-'||crlf||crlf;
-- write the message to the error log file
log_file_handle := UTL_FILE.FOPEN (log_file_dir, log_file_name, 'A',maxlinesize);
UTL_FILE.PUT_LINE(log_file_handle,msg);
UTL_FILE.FCLOSE(log_file_handle);
-- send the message by Email
mail_conn := UTL_SMTP.open_connection(smtp_relay, mail_port);
UTL_SMTP.HELO(mail_conn, smtp_relay);
UTL_SMTP.MAIL(mail_conn, sender_address);
UTL_SMTP.RCPT(mail_conn, recipient_address);
UTL_SMTP.DATA(mail_conn, msg);
UTL_SMTP.QUIT(mail_conn);
END IF; -- client_program = MyProgram.exe
END IF;
END;
/
Maybe you are looking for
-
Error with the creative Muvo V
hi, my new creative Muvo vidz screen is slowly turning black, it happend on my old one as well and bought a new one, now this one which i have only had for 3 weeks is now doing the same. any help is greatly appreciated. Thank you Kiara_C
-
Macbook Pro Temperatures. Normal Temps?
I just got a 2011 15" Macbook Pro. I installed the iStat Pro widget to monitor performance etc but I'm not sure how to interpret the temps. Could anyone fill me in on what the average temps should be for the various temp readings this provides? What'
-
I used time machine, now my drive has failed and all my files are lost.
i used time machine, now my drive has failed and all my files are lost. any one know how to get the max osx to see the drive again so i can retrive my files
-
Post install package installation on RHEL5
Hi, Can I have some advise please. When I installed Oracle's RHEL5 Linux OS I failed to select quite a lot of packages that I needed (like Apache for example.) I've been double clicking on the RPM packages and getting lots of dependacy errors and sea
-
Is there a way to watch wmv on Safari?
I'm running Snow Leopard, QT7, Flip4Mac.... In Leopard 10.5, the site like http://mtv.uol.com.br/noar was looking for a 'embedded' wmv player, with no answer, so it launched on the QT's window via Flip4Mac. And that worked OK. Now Safari doesn't laun