?
Solved

How to get TABLE NAME in trigger

Posted on 2005-03-29
5
Medium Priority
?
6,023 Views
Last Modified: 2008-10-27
I have come up with a trigger(insert delete update on TAB) which calls a standardized package that inserts query information into a custom table. We want to use this same package for triggers on multiple tables. I am having problems capturing the table name.

Is there any function that gives me the name of triggering table.... in our case TAB
I tried dbms_stanadard.dictionary_obj_name, tried ora_dict_obj_name too..... both are not working. I see the table column as empty.

Any ideas!
Thx
0
Comment
Question by:csreeni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Assisted Solution

by:neo9414
neo9414 earned 150 total points
ID: 13654539
This is what I understand..
You have triggers on each table.
you have a standard package (which is being called from the triggers).

If this is correct..then why don't you just pass the table name as parameter to the package (you already know the table name from the trigger info..create trigger...on tablename.....)

0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 150 total points
ID: 13656554
neo:
They don't like that approach.  This is a followup to:
http://www.experts-exchange.com/Databases/Oracle/Q_21364106.html
0
 
LVL 35

Assisted Solution

by:Mark Geerlings
Mark Geerlings earned 75 total points
ID: 13656764
Usually in Oracle, table triggers are "hard-coded" for each table with the table and column names fixed (not dynamic).  This is in keeping with PL\SQL's custom of using "early binding" of object names in SQL statements in PL\SQL code to database objects at compile time, to support faster execution times.

If you are willing to give up some runtime performance for the flexiblity of dynamic SQL in PL\SQL triggers and/or procedures, that may be possible, but it is likely more of a problem in triggers than in procedures.  Also, if you do find a way to do this in triggers, you will want to test the performance difference between dynamic and standard (static) SQL code in PL\SQL, especially if you have an OLTP system, to make sure that you don't introduce a performance penalty that the users do not like.
0
 

Expert Comment

by:AdissonRuiz
ID: 22803616
DECLARE @TriggerID INT
DECLARE @SelectSql VARCHAR(8000)

SET @TriggerID = @@PROCID;
SELECT @TableID = parent_id FROM sys.triggers  WHERE object_id = @TriggerID
SELECT @TableName = OBJECT_NAME(@TableID)
0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 22811566
To AddisonRuiz:
The syntax in your suggestion is *NOT* valid Oracle syntax.  Maybe that works in SQL Server, but it certainly will not work in an Oracle database!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question