Trigger Oracle (INSERT ONLY) question (Table of historical data)
What I have to do is follow the changes that are taking place on a table. The requirement is that it must be a trigger. The question I have is that a MERGE statement is moving data to another table that I monitor, which creates tons of changes (which are really just duplicates).The underside of work... with the exception of INSERTING it. When a change or remove met him, archives... but not INSERT it. I noticed that when I put where when to '=' instead of '<>', INSERTS will be saved (but obviously when new old =, which I don't want). The problem seems to be the "WHEN".
Any suggestions...?
CREATE OR REPLACE TRIGGER SCHEME. TRIGGERTEST22
After you INSERT or DELETE or update T_RESOURCE_ENTITY
THE ONTARIO SCHEME. TABLE
FOR EACH LINE
WHEN (nvl (new. T_RESOURCE_ENTITY, 'YYY') <>NVL (former. T_RESOURCE_ENTITY, "XXX"))
BEGIN
IF (VALUES) THEN
INSERT IN THE SCHEMA. TABLE_HISTORY2 (ARCHIVED_BY, ARCHIVED_DATE, ARCHIVED_TYPE, COLUMN_NAME, COLUMN_VALUE_NEW, COLUMN_VALUE_OLD)
VALUES ('USERNAME', SYSDATE, 'IN',: new.) T_RESOURCE_TYPE,: new. T_RESOURCE_ENTITY,: old. T_RESOURCE_ENTITY);
ELSIF (UPDATE) THEN
INSERT IN THE SCHEMA. TABLE_HISTORY2 (ARCHIVED_BY, ARCHIVED_DATE, ARCHIVED_TYPE, COLUMN_NAME, COLUMN_VALUE_NEW, COLUMN_VALUE_OLD)
VALUES ('USERNAME', SYSDATE, 'UP',: new.) T_RESOURCE_TYPE,: new. T_RESOURCE_ENTITY,: old. T_RESOURCE_ENTITY);
ELSIF (DELETING) THEN
INSERT IN THE SCHEMA. TABLE_HISTORY2 (ARCHIVED_BY, ARCHIVED_DATE, ARCHIVED_TYPE, COLUMN_NAME, COLUMN_VALUE_NEW, COLUMN_VALUE_OLD)
VALUES ('USERNAME', SYSDATE, 'DEL',: new.) T_RESOURCE_TYPE,: new. T_RESOURCE_ENTITY,: old. T_RESOURCE_ENTITY);
END IF;
END;
: old is NOT available to INSERT.
This means a trigger will not be enough.
-----------
Sybrand Bakker
Senior Oracle DBA
Tags: Database
Similar Questions
-
trigger for insertion of a table to another table
Hello again,
I tried to write a trigger after insert or update will happen in table 1, it will move some values in another table, as shown below:
Create or replace trigger Insert_Amount_Credit after insert or update on Reciept_Voucher
Referencing NEW AS NEW OLD OLD FOR EACH LINE AS
StartInsert into customer_Details (Transaction_Date, client_name, Description, credit) values (new. Rec_Date, new. Client_name, CONCAT (' receipt number:', again.) Rec_ID), new. Amount);
End;
/
The trigger was created but with compilation error... and my question is:
1. How do I write the code above in the best way?
2. How can I enough the other table with a table concatenated as what I was trying to make above?
any idea?
Something like that?
CREATE OR REPLACE TRIGGER trig_ins_testtrg2
BEFORE INSERT OR UPDATE ON test_trg1
FOR EACH LINE
BEGIN
INSERT INTO test_trg2 (curr_date,
job_id,
reason,
credit)
VALUES (SYSDATE,
: NEW.id,.
: NEW.receipt_no |:NEW.description,.
(: NEW.amount);
END;
-
Update the values in the Table from another Table containing historical data
So, I have two tables, a table and a master table. The current table is updated each week and at the end of the week, is copied to the main table to keep historical data. I have update the table in progress early in the week and want to take the latest data from the master table and update the current table with the data. The current table could have additional IDs or some of the IDS could have deposited (these lines would receive data in the main table). I want to only update the rows in the current table that have existing data to the attr1, attr2, attr3 columns. A particular ID may have more than one record in the primary table, I want only the last disk to use for updating the current table. The data from a different database where no direct connection is possible then I have to import data every week. Here are some statements of create/insert:
create table current_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
create table Master_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
begin insert into current_T (ID1,adate) values ('IE111','08/02/13'); insert into current_T (ID1,adate) values ('IE112','08/02/13'); insert into current_T (ID1,adate) values ('IE113','08/02/13'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE111','08/01/13','yes','abc','123'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE112','08/01/13','no','dgf','951'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE113','08/01/13','no','dgf','951'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE113','07/01/13','no','dgf','951'); end;
This has been a scratcher for me head and any help would be greatly appreciated. I'm coding in Apex 4.1
Thank you
-Steve
Not tested
merge into current_t c
using (select *)
Of
(select m.*
row_number() over (partition by m.id1 m.adate DESC order) rn
of master_t m
)
where rn = 1
) u
on (c.id1 = u.id1)
When matched then update
Set c.adate = u.adate
c.attr1 = u.attr1,
c.attr2 = u.attr2,
c.attr3 = u.attr3,
When not matched then insert
(c.id1, c.adate, c.attr1, c.attr2, c.attr3)
values
(u.id1, u.adate, u.attr1, u.attr2, u.attr3)
;
-
Oracle PL SQL Question to get some data to oracle tables descrepancy
Version of database
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE Production 9.2.0.8.0
AMT for HP - UX: 9.2.0.8.0 - Production Version
NLSRTL Version 9.2.0.8.0 - Production
created a few sample data
drop table tab1 purge;
create table tab1 (DEPT_ID COMP, qc_subtype_id char (4), EQUIP_CODE varchar2 (20), create_time date);
Insert into tab1 values(13,'1026','HEMORYA011',sysdate);
Insert into tab1 values(13,'1012','HEMORYA011',sysdate);
Insert into tab1 values(95,'1026','HEMORYA121',sysdate);
Insert into tab1 values(95,'1012','HEMORYA121',sysdate);
----------------------
Insert into tab1 values(13,'1026','HEMORYA014',sysdate);
Insert into tab1 values(13,'1012','HEMORYA005',sysdate);
Insert into tab1 values(13,'1012','HEMORYA013',sysdate);
Insert into tab1 values(95,'1012','HEMORYA013',sysdate);
Insert into tab1 values(95,'1012','HEMORYA148',sysdate);
commit;
I need to get a query to get the records of the gap
Dept HEMORYA014 13 lack 1012
HEMORYA005 dept 12 lack 1026
Dept HEMORYA013 13 lack 1026
The dept 95 lack 1026 HEMORYA013
The dept 95 lack 1026 HEMORYA148
I want to show the latter on the report
Thanks in advance.Thanks for posting a unit test.
I hope it will work for you, but maybe you will need to set the WHERE clause (add additional predicates).SQL> select equip_code 2 from ( select equip_code 3 , count(distinct qc_subtype_id) 4 from tab1 5 group by equip_code 6 having count(distinct qc_subtype_id)<2 7 ) 8 order by equip_code; EQUIP_CODE -------------------- HEMORYA005 HEMORYA013 HEMORYA014 HEMORYA148
-
UPDATE/INSERTION of a table full of data to an empty table.
Hi all
I use Oracle 11g - 64 bit and the client of TOAD.
I have two tables... a TMP_SUPP_CONTACTS (TMP) and table TBL_SUPP_CONTACTS (TBL). The TMP table has all these 'raw data ' (lower case), do not cut, etc. The Bill of lading DIRECT is completely empty, in addition to the columns. I need to move these data from the TMP table to the Bill of lading DIRECT.
The columns in each table do like this:
TMP:
CNTCT_ID
SUPP_IDNT
FIRST_NM
MID_NM
LAST_NM
ROLE_TITLE
ADDR_LN_1
ADDR_LN_2
ADDR_LN_3
CITY_NM
STATE_CD
POST_ZN_CD
CTRY_CD
PH_NUM
EMAIL_ADR_TXT
TBL:
ORG_ID
CNTCT_ID
SUPP_CD
DATA_SOURCE
ROLE_TITLE
FIRST_NM
LAST_NM
ADDR_ST
ADDR_CITY_NM
ADDR_ZIPCD
ADDR_CNTRY_CD
PH_NUM
ADDR_EMAIL
ADD_DT
LAST_UPD_DT
I am combining table TMP, ADDR_LN_1 + ADDR_LN_2 + ADDR_LN_3 at ADDR_ST in the Bill of lading DIRECT. My code looks like this...
UPDATE TBL_SUPP_CONTACTS TBLSC
SET
TBLSC.ORG_ID = "XXX."
TBLSC. CNTCT_ID = TRIM (UPPER (TMPSC. CNTCT_ID)),
TBLSC. SUPP_CD = TRIM (UPPER (TMPSC. SUPP_IDNT)),
TBLSC. DATA_SOURCE = 'E ',.
TBLSC. ADDR_ST = TRIM (UPPER (TMPSC. ADDR_LN_1))
|| ' '
|| TOPPING (UPPER (TMPSC. ADDR_LN_2))
|| ' '
|| TOPPING (UPPER (TMPSC. ADDR_LN_3)),
TBLSC. ADDR_CITY_NM = TRIM (UPPER (TMPSC. CITY_NM))
|| ' '
|| TOPPING (UPPER (TMPSC. STATE_CD)),
TBLSC. ADDR_CNTRY_CD = TRIM (UPPER (TMPSC. CTRY_CD)),
TBLSC. ADDR_EMAIL = TRIM (UPPER (TMPSC. EMAIL_ADR_TXT)),
TBLSC. ADDR_ZIPCD = TRIM (UPPER (TMPSC. POST_ZN_CD)),
TBLSC. FIRST_NM = TRIM (UPPER (TMPSC. FIRST_NM)),
TBLSC. LAST_NM = TRIM (UPPER (TMPSC. LAST_NM))
|| ' '
|| TOPPING (UPPER (TMPSC. MID_NM)),
TBLSC. PH_NUM = TRIM (UPPER (TMPSC. PH_NUM)),
TBLSC. ROLE_TITLE = TRIM (UPPER (TMPSC. ROLE_TITLE)),
TBLSC. LAST_UPD_DT = SYSTIMESTAMP,
TBLSC. ADD_DT = MARCH 6, 2013.
OF TMP_SUPP_CONTACTS TMPSC;
So, I have a few questions.
1. why this code does not work? It gives me an error on my statement FROM. I am new to Oracle and SQL as a whole, but trying my best to understand this.
2. for the TBLSC. Field LAST_UP_DT... I would format the SYSTIMESTAMP in MM/DD/YYYY format, is this possible to do?
Thanks to all the advice I receive for this problem. I appreciate it.Well, for starters, you want an INSERT... SELECT... statement, not an UPDATE statement. You have nothing to TBL to update, you will need to insert the data.
-
insert into the table using dynamic data
Oracle form 6i
Hai
I need to insert data into a table. I have generated my data text file with data in a form, now I need to insert data into a table. How can insert my field at that table if it is given in the table, I need to update, and there is no data I need to insert... Pls tell me the solution...
Concerning
Srikkanth.MCreate the trigger of the sur-insert and check the data are thre or not through the value of the primary key in this trigger. If the data is thre then update or it is then do not insert in the same trigger.
Thank you
SUN -
Create the trigger after insert
Hello
I would like to ask how to create a trigger after insert on a table. Basically, what I wanted to do are when an insert to table1 it will insert the records to table2. But the problem is that folders that will be inserted in the new tables are entries/fields, who lived in NEW York City (on table of ld)
after insertion, I wanted to add another field in table2 as status
create table table1)
Name varchar2 (55),
City varchar2 (55)
);
create (table2)
Name varchar2 (55)
status int (1)
)
Hope you could help me.
Thank you
Best regardsantok1015 wrote:
HelloI would like to ask how to create a trigger after insert on a table. Basically, what I wanted to do are when an insert to table1 it will insert the records to table2.
It's easy...
SQL> create table table1( 2 Name varchar2(55), 3 City varchar2(55) 4 ); Table created. SQL> SQL> create table table2 ( 2 Name varchar2(55), 3 status number(1) 4 ); Table created. SQL> SQL> create or replace trigger trg_tbl1 after insert on table1 2 for each row 3 begin 4 insert into table2 values (:new.name, 1); 5 end; 6 / Trigger created. SQL> insert into table1 values ('Fred','Bob'); 1 row created. SQL> select * from table2; NAME STATUS ------------------------------------------------------- ---------- Fred 1 SQL>
But the problem is that folders that will be inserted in the new tables are entries/fields, who lived in NEW York City (on table of ld)
after insertion, I wanted to add another field in table2 as status
This is not sensible. Please explain what you mean.
-
historical data in the repository with regard to targets?
Hi all
I have a question regarding the historical data. We have a CMS 11.1 and 11.2 repository DB. And lots of DB/target, download data to WHO. Our question to what extent rear can be go and watch performace data?
Who is still dependent on the AWR retention policy (our current retention during most of our database are 30 days) on the DB or is there a setting where I can tell all in WHO or repository DB saying I want to store the CWA or any retention performance for lets say 6 months? How can I do this? I won't put in AWR retention to 6 months on the actual target db. Anyway is the objectifdes AWR data to db repository?See the documentation
Oracle® Enterprise Manager Administration
11g Release 1 (11.1.0.1)
http://download.Oracle.com/docs/CD/E11857_01/EM.111/e16790/repository.htm#i1030660for data retention strategies.
The configuration of the AWR reflects only a guarded target database.
The data collected (Agents) will be stored in the repository and is subject to the policies of data retention.
Concerning
Rob
http://oemgc.WordPress.com -
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE Production 11.2.0.4.0
AMT for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
I create the structure of the table like that.
create table test1 (a primary key, b (2) char number, date c, d varchar2 (10), date of e);
create table test2 (number of ab, cd (2) tank, date of the ef, gh varchar2 (10), date of the ij, kl varchar2 (100));
Create materialized view log on test1;
create materialized view fast refresh test1_v on commit in select * from test1;
I have create a trigger of the sample
CREATE OR REPLACE TRIGGER test1_trig
AFTER INSERT OR UPDATE OR DELETE
ON test1_v
FOR EACH LINE
DECLARE
lr_test2 test2% ROWTYPE;
lv_error VARCHAR2 (4000);
BEGIN
lr_test2. AB: =: NEW.a;
lr_test2. CD: =: NEW.b;
lr_test2. GH: =: NEW.d;
IF THE INSERTION
THEN
lr_test2. EF: = SYSDATE;
lr_test2.IJ: = SYSDATE;
lr_test2.KL: = 'INSERT ';
INSERT INTO test2
VALUES lr_test2;
ELSIF UPDATE
THEN
lr_test2.IJ: = SYSDATE;
lr_test2.KL: = 'UPDATE ';
UPDATE test2 = lr_test2 ab WHERE = LINE: OLD.a;
ELSIF REMOVAL
THEN
DELETE FROM test2
AB = WHERE: old.a;
END IF;
EXCEPTION
WHILE OTHERS
THEN
lv_error: = SQLERRM;
INSERT INTO XXDOMINO_FG_DATA_LOAD_ERROR
VALUES ('test1_trig',
: OLD.a,.
"test1_trig,"
LV_ERROR,
SYSDATE);
COMMIT;
END test1_trig;
/
So, if check you my code,.
When I insert EF = SYSDATE, IJ = SYSDATE.
Update EF is not changed, IJ = SYSDATE.
So I like to capture their insertion and update dates.
But if updates or insert arrives on the materialized table. The trigger themselves as an INSERT only.
So how do you capture the updates?
I use the statemnet with out merger with performance and also able to capture the update dates.
CREATE OR REPLACE TRIGGER test1_trig_merge
AFTER INSERT OR UPDATE OR DELETE
ON test1_v
FOR EACH LINE
DECLARE
lr_test2 test2% ROWTYPE;
lv_error VARCHAR2 (4000);
BEGIN
IF THE REMOVAL
THEN
DELETE FROM test2
AB = WHERE: old.a;
ELSIF INSERTION
THEN
MERGE INTO test2 one
B using (SELECT 1 FROM DUAL)
WE (ab =: new.a)
WHEN MATCHED
THEN
UPDATE the VALUE ab =: NEW.a.
CD =: NEW.b,
GH =: NEW.c
IJ = SYSDATE,
KL = "Update"
AB WHERE =: old.a
WHEN NOT MATCHED
THEN
INSERTING VALUES (: NEW.a,)
: NEW.b,.
: NEW.c.
: NEW.d,.
: NEW.e,.
"INSERT");
END IF;
EXCEPTION
WHILE OTHERS
THEN
lv_error: = SQLERRM;
INSERT INTO XXDOMINO_FG_DATA_LOAD_ERROR
VALUES ('test1_trig',
: OLD.a,.
"test1_trig,"
LV_ERROR,
SYSDATE);
END test1_trig_merge;
/
DISPLAY ERRORS;
-
Mr President.
I create a form based on two tables that have sequences also. When I create insert only row is inserted in the fields in table first and second fields of the table are empty. Why?
the page source is
<?xml version='1.0' encoding='UTF-8'?> <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:af="http://xmlns.oracle.com/adf/faces/rich" xmlns:f="http://java.sun.com/jsf/core"> <af:panelFormLayout id="pfl1"> <af:group id="Group"> <af:inputText value="#{bindings.VoucherId.inputValue}" label="#{bindings.VoucherId.hints.label}" required="#{bindings.VoucherId.hints.mandatory}" columns="#{bindings.VoucherId.hints.displayWidth}" maximumLength="#{bindings.VoucherId.hints.precision}" shortDesc="#{bindings.VoucherId.hints.tooltip}" id="it1"> <f:validator binding="#{bindings.VoucherId.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.VoucherId.format}"/> </af:inputText> <af:inputDate value="#{bindings.VoucherDate.inputValue}" label="#{bindings.VoucherDate.hints.label}" required="#{bindings.VoucherDate.hints.mandatory}" columns="#{bindings.VoucherDate.hints.displayWidth}" shortDesc="#{bindings.VoucherDate.hints.tooltip}" id="id1"> <f:validator binding="#{bindings.VoucherDate.validator}"/> <af:convertDateTime pattern="#{bindings.VoucherDate.format}"/> </af:inputDate> <af:inputText value="#{bindings.Credit.inputValue}" label="#{bindings.Credit.hints.label}" required="#{bindings.Credit.hints.mandatory}" columns="#{bindings.Credit.hints.displayWidth}" maximumLength="#{bindings.Credit.hints.precision}" shortDesc="#{bindings.Credit.hints.tooltip}" id="it2"> <f:validator binding="#{bindings.Credit.validator}"/> </af:inputText> </af:group> <af:group id="g1"> <af:inputText value="#{bindings.Lineitem.inputValue}" label="#{bindings.Lineitem.hints.label}" required="#{bindings.Lineitem.hints.mandatory}" columns="#{bindings.Lineitem.hints.displayWidth}" maximumLength="#{bindings.Lineitem.hints.precision}" shortDesc="#{bindings.Lineitem.hints.tooltip}" id="it3"> <f:validator binding="#{bindings.Lineitem.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.Lineitem.format}"/> </af:inputText> <af:inputText value="#{bindings.VoucherId1.inputValue}" label="#{bindings.VoucherId1.hints.label}" required="#{bindings.VoucherId1.hints.mandatory}" columns="#{bindings.VoucherId1.hints.displayWidth}" maximumLength="#{bindings.VoucherId1.hints.precision}" shortDesc="#{bindings.VoucherId1.hints.tooltip}" id="it4"> <f:validator binding="#{bindings.VoucherId1.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.VoucherId1.format}"/> </af:inputText> <af:inputText value="#{bindings.Debit.inputValue}" label="#{bindings.Debit.hints.label}" required="#{bindings.Debit.hints.mandatory}" columns="#{bindings.Debit.hints.displayWidth}" maximumLength="#{bindings.Debit.hints.precision}" shortDesc="#{bindings.Debit.hints.tooltip}" id="it5"> <f:validator binding="#{bindings.Debit.validator}"/> </af:inputText> <af:inputText value="#{bindings.Credit1.inputValue}" label="#{bindings.Credit1.hints.label}" required="#{bindings.Credit1.hints.mandatory}" columns="#{bindings.Credit1.hints.displayWidth}" maximumLength="#{bindings.Credit1.hints.precision}" shortDesc="#{bindings.Credit1.hints.tooltip}" id="it6"> <f:validator binding="#{bindings.Credit1.validator}"/> </af:inputText> <af:inputText value="#{bindings.Particulars.inputValue}" label="#{bindings.Particulars.hints.label}" required="#{bindings.Particulars.hints.mandatory}" columns="#{bindings.Particulars.hints.displayWidth}" maximumLength="#{bindings.Particulars.hints.precision}" shortDesc="#{bindings.Particulars.hints.tooltip}" id="it7"> <f:validator binding="#{bindings.Particulars.validator}"/> </af:inputText> <af:inputText value="#{bindings.Amount.inputValue}" label="#{bindings.Amount.hints.label}" required="#{bindings.Amount.hints.mandatory}" columns="#{bindings.Amount.hints.displayWidth}" maximumLength="#{bindings.Amount.hints.precision}" shortDesc="#{bindings.Amount.hints.tooltip}" id="it8"> <f:validator binding="#{bindings.Amount.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.Amount.format}"/> </af:inputText> </af:group> <f:facet name="footer"> <af:button text="Submit" id="b1"/> <af:button actionListener="#{bindings.CreateInsert.execute}" text="CreateInsert" disabled="#{!bindings.CreateInsert.enabled}" id="b2"/> <af:button actionListener="#{bindings.Commit.execute}" text="Commit" disabled="#{!bindings.Commit.enabled}" id="b3"/> <af:button actionListener="#{bindings.Rollback.execute}" text="Rollback" disabled="#{!bindings.Rollback.enabled}" immediate="true" id="b4"> <af:resetActionListener/> </af:button> </f:facet> </af:panelFormLayout> </ui:composition>
Concerning
Go to your VO Wizard, select the tab of the entity and to check if both the EO is editable or not.
See you soon
AJ
-
table is expected to insert only one line
Hi all
my need is to create the table that allows to insert only one line.
How can I make it?
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
Hello
2621671 wrote:
Hi all
my need is to create the table that allows to insert only one line.
How can I make it?
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
You can create a unique Index based on a function, like this:
CREATE UNIQUE INDEX table_x_u ON table_x (NVL2 (col_1, 1, 1));
You can use any column of any data type. In other words, the function may return a NUMBER, if the column referenced in the function is a NUMBER.
Regardless of whether the column is NULL or not; not more than 1 rank is authorized.
-
Trigger with a problem - insert only situation where not exists
Hello experts!
I have a problem with a trigger, that I am creating. It compiles, but I get an error message when the trigger is activated.
The scenario is as follows:
I have a TBL_PUNKTDATEN table. Whenever the State of a record in this table is passed to 3 or 4 I need the trigger to insert a dataset object in my target (TBL_ARBEIT_ZU_GEBIET) table.
However, the trigger must insert data only when there is no existing record in the target table. The condition that specifies whether or not, there is a group of data is the LNG_GEBIET field, which exist in the source as well as in the target table. Therefore, for every LNG_GEBIET there may be only one set of data in the table target!
I created a trigger using the following code. However, it does not work.
Maybe you'll see what I want to achieve at a glance to my code.
Can you please help me on this one?
Thank you very much!
Sebastian
Well, on the first insert the code works correctly and inserts the recordset as expected. However, if there is an existing recordset object where: new. LNG_GEBIET corresponds to LNG_Gebiet in my target table, I get the error ORA-06502!create or replace TRIGGER set_status_arbeit_zu_gebiet AFTER UPDATE ON TBL_PUNKTDATEN FOR EACH ROW WHEN(new.INT_STATUS=3 or new.INT_STATUS=4) declare cursor c is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET; x number; begin open c; fetch c into x; if c%NOTFOUND then INSERT INTO TBL_ARBEIT_ZU_GEBIET ( LNG_GEBIET, LNG_ARBEITSSCHRITT, PNUM, INT_BEARBEITER, DATE_DATUM, GEPL_DATUM ) VALUES (:new.LNG_GEBIET, 52, 1114, 895, sysdate, to_date('01.01.1990', 'DD.MM.YYYY') ); end if; end;
Maybe spcifies it a little?
I hope you can help me!
Thank you!
Edited by: skahlert the 23.09.2009 10:26
Edited by: skahlert the 23.09.2009 10:28Hi Sebastian,.
Looks like LNG_GEBIET is not a data type of NUMBER?
Trying to change that
declare cnumber number; cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET; begin open c2; fetch c2 into cnumber;
in
declare cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET; v_c2 c2%ROWTYPE; begin open c2; fetch c2 into v_c2;
This way you don't care datatypes or number of fields in the cursor c2.
Concerning
Peter -
How to identify the name of the procedure that inserts into a table in the TRIGGER
Hello
There are several procedures in my DB that perform the INSERT operation on a main table - MYTAB say.I created a trigger on the table MYTAB, to follow closely, what procedure is insert data in there. Is there a function that captures the name of this object?
For example: PROC_A, PROC_B, PROC_C insert into the table MYTAB. And my query is - the trigger on table MYTAB should document these object names where the lines fit.
Please let me know your suggestions...SQL> create table t (no integer, dt timestamp, who_inserted varchar2(4000)); Table created. SQL> create or replace procedure p 2 as 3 begin 4 insert into t (no, dt) values (1, systimestamp); 5 end; 6 / Procedure created. SQL> show err No errors. SQL> create or replace trigger t_trig before insert on t for each row 2 begin 3 :new.who_inserted := dbms_utility.format_call_stack; 4 end; 5 / Trigger created. SQL> show err No errors. SQL> begin 2 p; 3 end; 4 / PL/SQL procedure successfully completed. SQL> select * from t; NO DT WHO_INSERTED ---------- ------------------------------ ---------------------------------------- 1 31-OCT-14 04.58.53.668465 AM ----- PL/SQL Call Stack ----- object line object handle number name 3a7ddbea0 2 KARTHICK.T_TRIG 3ac979f30 4 procedure KARTHICK.P 3a822deb8 2 anonymous block
-
trigger after insert in tables MASTER DETAILS, adding bonuses to employees
Hi Experts, I am a beginner in PL/SQL and triggers
=========================
I have two tables:
MASTER (DOC_NO, DOC_DATE, BONUS)
DETAILS (EMP_NO, EMP_NAME, EMP_BONUS)
I need to distribute the (BONUS) column in table (MASTER) to column (EMP_BONUS) in DETAILS
by equal parts.
I need it in (trigger after insert)
EMP_BONUS: is BONUS count (EMP_NO);.
example:
BONUS = 100
No EMP_NO = 20
This means (EMP_BONUS = 100/20 = 5).
I use the 6.0 with 9i DB form
Help, pleaseRARA says:
Hi Experts, I am a beginner in PL/SQL and triggers
=========================
I have two tables:
MASTER (DOC_NO, DOC_DATE, BONUS)
DETAILS (EMP_NO, EMP_NAME, EMP_BONUS)I need to distribute the (BONUS) column in table (MASTER) to column (EMP_BONUS) in DETAILS
by equal parts.
I need it in (trigger after insert)
EMP_BONUS: is BONUS count (EMP_NO);.
example:
BONUS = 100
No EMP_NO = 20This means (EMP_BONUS = 100/20 = 5).
I use the 6.0 with 9i DB form
Help, pleaseIf you want to do after insertion and forms... You can use the trigger to insert after and try something like this
declare a number; begin select count(emp_no) into a from master; update details set emp_bonus=:bonus/a; commit; end;
Hope this helps
If someone useful or appropriate, please mark accordingly.
-
Same question different results when insert into one table.
Hello
I have an insert statement as below.
insert into mid_table_name
Select seq.nextval key1, Field1, Field2,...)
Select Field1, Field2 b.test2 a.test1...
tab1 tab2 a and b
where a.key1 = b.key1
and...
...
)
When I run the present, it's inserting less files that actually, the subquery returns.
I noticed that
(1) when I run the subquery, illustrated below, it returns more than 60 lines of k which is what I expect.
(select Field1, Field2 b.test2 a.test1...
tab1 tab2 a and b
where a.key1 = b.key1
and...
...
)
(2) However, when I run including the outer query, showb below, it returns only about 8 k; the same is get inserted into the table.
Select seq.nextval key1, Field1, Field2,...)
Select Field1, Field2 b.test2 a.test1...
tab1 tab2 a and b
where a.key1 = b.key1
and...
...
)
Any help will be greatly appreciated.
Thank you
PrepYou can try this one.
Select seq.nextval, ff.*
Select * from)
Select Field1, Field2 b.test2 a.test1...
tab1 tab2 a and b
where a.key1 = b.key1
and...
...
)
FF
Maybe you are looking for
-
YouTube is slowing down my computer! Any suggestions?
Hello dear friends, I have a good MacBook Pro 2013 retina with i7 and SSD. I have noticed occasionally when I Watch youtube videos and try to make comments, while I type it needs some time to let the letters appear. Is like takes me a lot of energy a
-
I have an account for my Podcast. I publish the RSS and posts go to the each subscriber of iTunes accounts but do not publish in the iTunes store. I changed servers recently and have, in my opinion, done all correct use for my stream change... help
-
computer does not start on the first attempt
When I turn on my computer it stops down in front of him actually starts to run, it takes several attempts before I can run. Im running windows vista 32-bit home
-
NEED HELP OR MY SŒUR IS GOING TO KILL ME
I have a problem with my laptop, I used it and suddenly it froze and I had to reboot, when I did that it remained all black for awhile then it took me a blue screen saying, "recovery."Your pc needs to be repaired, a required device is not connected o
-
Recommendations for the collection of NICs (<>- SG200 vSwitches)
Hello Are there settings specific to the SG200-26 when it is used with ESXi vSwitches (in a configuration of load balancing) For example 2 guests, 4 network adapters per host, each NETWORK card transfer traffic from 2-3 networks VIRTUAL (junction por