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


Please Help Members By Posting Answers For Below Questions

What are the operators in sql?

540


How can we connect an Android App to an Oracle database and use the PL/SQL procedural code?

593


What do you mean by rowid?

548


What is embedded sql what are its advantages?

519


What is the difference between having and a where in sql?

592






what is the difference between join and union? : Sql dba

558


What is sql profiler in oracle?

572


How to select unique records from a table?

577


How many rows can sqlite handle?

604


How do you remove duplicates without using distinct in sql?

516


how tsql statements can be written and submitted to the database engine? : Transact sql

544


What is a unique constraint?

620


What is rank dense_rank and partition in sql?

551


How do you update f as m and m as f from the below table testtable?

1126


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

1733