1

i have a store procedure which is called by 4 different trigger is it possible to get trigger's information like name when the procedure is executed.

i can do it by passing a extra parameter to the procedure, is there any other option? i am using oracle 11g. Thanks

2
  • You can add an additional parameter to the procedure to pass this trigger name. Commented Nov 7, 2013 at 12:44
  • Unfortunately, triggers apparently do not appear in the stack backtrace. See stackoverflow.com/questions/7032373/… how to get the stacktrace but in my tests, the trigger name is not included. Commented Nov 7, 2013 at 12:49

2 Answers 2

2

You could use the function dbms_utility.format_call_stack which is documented here:

SQL> set serveroutput on
SQL> create table test_table (n number);

Table created.

SQL> create or replace procedure test_procedure as
  2  begin
  3     dbms_output.put_line(dbms_utility.format_call_stack);
  4  end;
  5  /

Procedure created.

SQL> create or replace trigger test_trigger_insert
  2  before insert on test_table
  3  for each row
  4  begin
  5     test_procedure;
  6  end;
  7  /

Trigger created.

SQL> create or replace trigger test_trigger_delete
  2  before delete on test_table
  3  for each row
  4  begin
  5     test_procedure;
  6  end;
  7  /

Trigger created.

SQL> rem direct execution of the procedure
SQL> exec test_procedure;
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name
0x2bc2f1ca0         3  procedure YOUR_SCHEMA.TEST_PROCEDURE
0x31a218568         1
anonymous block


PL/SQL procedure successfully completed.

SQL> rem procedure called by trigger test_trigger_insert
SQL> insert into test_table (n) values (42);
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name
0x2bc2f1ca0         3  procedure YOUR_SCHEMA.TEST_PROCEDURE
0x2adc40fb0         2
YOUR_SCHEMA.TEST_TRIGGER_INSERT


1 row created.

SQL> rem procedure called by trigger test_trigger_delete
SQL> delete from test_table where n = 42;
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name
0x2bc2f1ca0         3  procedure YOUR_SCHEMA.TEST_PROCEDURE
0x2f10ffd28         2
YOUR_SCHEMA.TEST_TRIGGER_DELETE


1 row deleted.
Sign up to request clarification or add additional context in comments.

1 Comment

got my problem solved,thank you @marco baldelli for your detailed answer
1

If your trigger is called My_Trigger you can try this:

SELECT Trigger_type, Triggering_event, Table_name
   FROM USER_TRIGGERS
   WHERE Trigger_name = 'My_Trigger';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.