If i insert record in table A and these record should update in table B by using Trigger.How to achieve this.
Answer Posted / anil
CREATE table trg_tab
(ename VARCHAR(10),
sal NUMBER);
/
CREATE table log_tab
(usr VARCHAR(10),
upd DATE,
ename VARCHAR(10),
sal NUMBER
);
/
CREATE OR REPLACE TRIGGER log_trg
AFTER INSERT ON trg_tab
FOR EACH ROW
DECLARE
v_user VARCHAR(10);
BEGIN
SELECT USER
INTO v_user
FROm DUAL;
INSERT INTO log_tab
VALUES (v_user,SYSDATE,:NEW.ename,:NEW.sal);
END;
/
INSERT INTO trg_tab
SELECT ename,sal FROm emp;
/
SELECT * FROm log_tab;
/
Is This Answer Correct ? | 7 Yes | 1 No |
Post New Answer View All Answers
What are the operators in sql?
How can we connect an Android App to an Oracle database and use the PL/SQL procedural code?
What do you mean by rowid?
What is embedded sql what are its advantages?
What is the difference between having and a where in sql?
what is the difference between join and union? : Sql dba
What is sql profiler in oracle?
How to select unique records from a table?
How many rows can sqlite handle?
How do you remove duplicates without using distinct in sql?
how tsql statements can be written and submitted to the database engine? : Transact sql
What is a unique constraint?
What is rank dense_rank and partition in sql?
How do you update f as m and m as f from the below table testtable?
Table 1: col1 Timestamp ---------------- 01-mar-2012 11:12:46 Table 2: col2 Timestamp -------------------- 01-mar-2012 11:12:10 01-mar-2012 11:11:23 Write a query to display a row with table2 col2 value less than tabl1 col1 value. Maximum timestamp value previous to table1 col1 value. Display a result as: Col1 col2 ----- ----- 01-mar-2012 11:12:46 01-mar-2012 11:12:10