Instead of Triggers On Views Example in Oracle

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

11/29/2018 Instead of Triggers on Views Example in Oracle

Home Data Warehouse Informatica Informatica Scenarios Informatica Cloud Oracle Unix Hadoop

Search... Search
Instead of Triggers on Views Example in Oracle
Instead of triggers in oracle database are defined on views only. A normal DML trigger executes
Popular Posts
only when a DML operation is issued on a table. Whereas instead of trigger fires when a DML Informatica Scenario Based Interview Questions with
statment is issued on the view. Instead-of triggers must be row level. Answers - Part 1

Unix Sed Command to Delete Lines in File - 15 Examples


Create Instead of Trigger - Example:
String Functions in Hive
Take a look at the following view defintion:
Top Examples of Awk Command in Unix

Create or replace view emp_dept_join as Sed Command in Unix and Linux Examples
Select d.department_id,
d.department_name, Design/Implement/Create SCD Type 2 Effective Date
Mapping in Informatica
e.first_name,
e.last_name Date Functions in Hive
from employees e,
departments d SQL Queries Interview Questions - Oracle Part 1
where e.department_id = d.department_id;
Top Unix Interview Questions - Part 1

Update Strategy Transformation in Informatica


As the view consists of two table joins, it is illegal to insert records into this view as the insert
requires both the underlying tables to be modified.
Have Questions? Follow Me
By creating an instead-of trigger on the view, you can insert the records into both the underlying
tables. An examples is shown below:

CREATE OR REPLACE TRIGGER insert_emp_dept


INSTEAD OF INSERT ON emp_dept_join
DECLARE
https://www.folkstalk.com/2012/12/instead-triggers-views-example-oracle.html 1/4
11/29/2018 Instead of Triggers on Views Example in Oracle

v_department_id departments.department_id%TYPE; vijay bhaskar


BEGIN Add to circles
BEGIN
SELECT department_id INTO v_department_id
FROM departments
WHERE department_id = :new.department_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
INSERT INTO departments (department_id, department_name)
VALUES (dept_sequence.nextval, :new.department_name)
RETURNING ID INTO v_department_id;
END;

INSERT INTO employees (employee_id, first_name, last_name, department_id)


VALUES(emp_sequence.nextval, :new.first_name, :new.last_name, v_depar
END insert_emp_dept;
994 have me in circles View all
/

6 comments:

Pradeep Sorari 08 July, 2013 09:14


Nice and easy way to explain !!
However I have a doubt , What is exactly "emp_dept_join" ?
Please elaborate .... Thanks
Reply

Replies

vijay bhaskar 08 July, 2013 21:38


emp_dept_join is a view

Reply

https://www.folkstalk.com/2012/12/instead-triggers-views-example-oracle.html 2/4
11/29/2018 Instead of Triggers on Views Example in Oracle

kranti kumar Challa 16 July, 2013 12:46


in RETURNING ID INTO v_department_id
what is id value?
Reply

Replies

vijay bhaskar 16 July, 2013 18:47


sequence value

Reply

vishal 23 May, 2017 07:03


so here we are inserting the details in each table employee nd department seperately.. Dat also
could be done through any procedure ri8? then were we inserting in view emp_dept_join ? i mean
what is the use of this instead of trigger to insert into view(emp_dept_join)? if we are inswrting
data to each table seperarely..
Reply

Unknown 25 May, 2017 22:02


every time we try to update/insert (any DML) a complex view ( which is generally not possible)
this trigger will fire and update/insert the respective tables from which the view is created with the
values given to insert/update.
Reply

Enter your comment...

Comment as: Google Accoun

Publish Preview

https://www.folkstalk.com/2012/12/instead-triggers-views-example-oracle.html 3/4
11/29/2018 Instead of Triggers on Views Example in Oracle

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

https://www.folkstalk.com/2012/12/instead-triggers-views-example-oracle.html 4/4

You might also like