When a new data with ename fields in the table, if new data ename in the table already exists, then in addition to the primary key to other fields are the same as the original data, and insert. If it does not have the same ename field values, don't do processing, directly inserted into the
For example, to create a empno for 9988, ename for SMITH's data, the other fields do not write, take the default, after the trigger, the new data for [empno: 9988, ename: SMITH, job: CLERK, MGR: 7902, hiredate: 17 - DEC - 80, sal: 800, comm: (null), deptno: 20] (empno is different, only the rest of the field is the same)
Don't know how to write such a trigger, a great god to solve, if the statement execution is best
CodePudding user response:
You ever written a similar trigger, can draw lessons from the trigger statement? Thank you very muchCodePudding user response:
The building Lord this requirement, consider change the insert to the merge statement, very suitable for your needs, nowMerge into syntax, baidu first, have a question to ask,
CodePudding user response:
Thank you very much for the second floor to answer, I'll go search under the usage of the mergeCodePudding user response:
The create or replace the trigger tri_insert_empyee
After
Insert
On an emp
For each row
Declare
The begin
- perform when insert
If the insert then
The merge into an emp e
Using (
- search new insert data (part of the field is empty, this screening)
Select * from emp where sal=null
Ee)
On (
- already empno is the same in the two tables, and wage salary isn't as empty as conditions in the table e
E.e name=ee. Ename and
E.s al!=null
)
The when matched then
- when matching, the new data fields in the assignment
Update the set (ee. Sal=e.s al)
When not matched then
- does not match the case, then insert directly, not fill in the fields to take an empty value ( not sure here, because when the trigger after insert trigger, the following data will lead to repeat the insert?
)Insert (e.e mpno, e.e name, e.j ob, e.m gr, e.h iredate, e.s al, e.com m, e.d eptno) values (ee) empno, ee, ename, ee, job, ee. MGR, ee, hiredate, ee, sal, ee.com m, ee, deptno);
End the if;
end;
ERROR: LINE/COL ERROR
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
3/8 PLS - 00103: a symbol of "INSERT" when need to be one of the following: (- + case mod new not null & lt; The an identifier> The continue avg count current exists Max min the prior SQL stddev sum variance execute forall the merge time timestamp interval date & lt; A string literal with character set specification> Error: check the compiler log
CodePudding user response: