Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 240 Big Data Appliance
- 1.9K Data Science
- 450.4K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 546 SQLcl
- 4K SQL Developer Data Modeler
- 187.1K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 443 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
dynamic trigger for after insert on a table

hi,
i need to create a trigger to insert into a table after a row is inserted into a table.But the issue I am facing is that I am not able to refer the entire row using :new.* so in case the structute of the table changes I would have to recreate the trigger.Is there any way to make the trigger dynamic for eg: like reading the column_names from dba_tab_columns and then using it in the query?
While trying to use the abobe case I am not able to convert the multiple rows returned from dba-tab_colums into a single row with many columns.
i.e I want to make
col
col1
col2
into
col col1 col2
3 rows into 3 columns how do I do this
Answers
-
It would make the trigger slow.
How frequently would you expect the table structure to change ? Part of your schema maintenance instructions would be to include the trigger changes with the table changes.
Hemant K Chitale
-
What is the actual business requirement here? I cant think of any reason you'd want to do this other than keeping a logical backup of your tables, but that is not the way you would go about it.
Triggers are generally not the solution to most problems.
-
The requiremnet is to replicat a few tables to a remote db which will include different schema tables.
-
Don't use a trigger to replicate data to a remote database. Network outage or non-availability of the remote database will prevent transactions on the local database.
Use Materialized Views (available in Standard Edition as well) or Advanced Replication (available in Enterprise Edition) or Golden Gate (separately priced product).
Hemant K Chitale
-
the statements inside the trigger are part of the actual transaction
if the remote site is unavailable, your statement won't work
if it's very remote you might have some slow issues
how *fast* do those changes have to get on the other site ?
-
These solutions all sound awfully complicated. A multitable insert through a database link might be faster, simpler, and more reliable,
http://docs.oracle.com/database/121/SQLRF/statements_9014.htm#i2125362
-
PL/SQL has a construct called SUBTYPE.
SUBTYPES allow <tablename>%ROWTYPE syntax.
You need to set up a procedure with a parameter which is defined as a SUBTYPE and passes the entire row as a PL/SQL record.
You need to recompile this procedure (it will be a procedure in a package, one package per table) everytime the table is ALTERED.
It is unclear to me why you 'need' this, it seems to be a recipe for disaster.
Also I don't understand why it is still too difficult for you to specify your four digit Oracle version.
You have been here long enough to know this is mandatory.
---------------
Sybrand Bakker
Senior Oracle DBA