Firing trigger to insert id in a table
I am not able to insert the ID in CR_ID details when i press the create button in Apex Master detail form & Tabular form.
CREATE OR REPLACE TRIGGER COSTMAN."CM_RECIPE_T1"
BEFORE INSERT ON "CM_RECIPE"
FOR EACH ROW
DECLARE
L_ID NUMBER;
BEGIN
SELECT CM_RECIPE_SEQ.NEXTVAL INTO L_ID FROM DUAL;
IF :NEW.CR_ID IS NULL THEN
:NEW.CR_ID := L_ID;
END IF;
END;
Do i have to write a process in Apex form. This is a first time, i've come across a situation where i want the column to get populated using a trigger when pressing a Create button in an Apex form.
Please suggest..
Yogesh
Hi
If the trigger is on the table, then it will be fired when an INSERT takes place, you don't need to code for it specially.
Do lovely SQL> CREATE TABLE insert_test
(col1 NUMBER,
col2 VARCHAR(2));
Table created.
Elapsed: 00:00:00.24
Do lovely SQL> CREATE SEQUENCE insert_seq
START WITH 1
MAXVALUE 999999999999999999999999999
MINVALUE 1;
Sequence created.
Elapsed: 00:00:00.00
Do lovely SQL> CREATE TRIGGER insert_trig
BEFORE INSERT ON insert_test
FOR EACH ROW
DECLARE
L_ID NUMBER;
BEGIN
SELECT insert_seq.NEXTVAL INTO L_ID FROM DUAL;
IF :NEW.col1 IS NULL THEN
:NEW.col1 := L_ID;
END IF;
END;
Trigger created.
Elapsed: 00:00:00.23
Do lovely SQL> INSERT INTO insert_test (col2) VALUES('TT');
1 row created.
Elapsed: 00:00:00.03
Do lovely SQL> COMMIT;
Commit complete.
Elapsed: 00:00:00.00
Do lovely SQL> SELECT * FROM insert_test;
COL1 CO
1 TT
Elapsed: 00:00:00.04See - you just need to do the insert.
Cheers
Ben
Similar Messages
-
Create Trigger to insert records from one table to another
I created the below trigger to move data from one table to another after records have been inserted from another table to that table. What I need done is that each time records have been inserted into TEST_TBL, one of these actions codes should be implimented: U-update, N-insert, D-delete and inserted into TEST_TBL1. But each time I run the script, I get bunch of errors. Please see the script below: - Your help will be appreciated.
create or replace
trigger POWER_tr
after update or insert or delete ON test_tbl
for each row
begin
if updating then
insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'U', sysdate);
ELSif INSERTING then
insert insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'N', sysdate);
ELSIF deleting then
insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'D', sysdate);
END IF;
END POWER_tr;
Thank you,
Albert Zaza
Edited by: azaza on Mar 1, 2009 4:14 PMHello
At the end of trigger show errors / and post what errors are you getting exactly?
Here is a simple example for your reference, this will save old values in history table; you can replace it with new values if that's what do you want.
CREATE OR REPLACE TRIGGER TRG_DU
AFTER DELETE OR UPDATE
ON EMPLOYEE REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
BEGIN
IF UPDATING
THEN
INSERT INTO employee_hist
VALUES ('UPDATE',
:OLD.empid,
:OLD.name,
:OLD.deptid);
ELSIF DELETING
THEN
INSERT INTO employee_hist
VALUES ('UPDATE',
:OLD.empid,
:OLD.name,
:OLD.deptid);
END IF;
EXCEPTION
WHEN OTHERS
THEN
-- Consider logging the error and then re-raise
RAISE;
END TRG_DU;
/Regards
Edited by: OrionNet on Mar 1, 2009 7:27 PM -
Trigger on Insert into a custom table from external application
This is the problem I am facing.
External Application using a different schema lets say extdb on a different server. This writes into a table in a schema called appscustom schema. Appscustom schema is under Oracle Apps.
A trigger in Oracle Apps to be executed on insert into the appscustom schema table.
This trigger inturn will run a concurrent job to create the invoice and gl interface tables.
THe problem I am facing is, The trigger get executed but the concurrent job does not get triggered/run.
Here is the trigger. Let me know, what might be wrong.
THe values for vRESP_APPL_Id,vRESP_ID, vUSER_ID becomes null in the test_pims table.
Whereas when I manually insert from backend into appscustom schema table the concurrent job gets submitted.
~~~~~~~~~~~~~~~~~~~~~~~~~~
-- Start of DDL Script for Trigger APPS.RWJF_PIMS_ORACLE_INT
-- Generated 5/25/2005 22:10:52 from APPS@HENRY_DEVL
CREATE OR REPLACE TRIGGER rwjf_pims_oracle_int
AFTER
INSERT
ON rwjf_pimstxnbatch
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
WHEN (new.status = 'U' )
Declare
ReturnCode BOOLEAN;
ConcReqID NUMBER := 0;
vRESP_APPL_ID NUMBER;
vRESP_ID NUMBER;
vUSER_ID NUMBER;
LoadToAp NUMBER :=0;
LoadToGl NUMBER :=0;
Begin
-- vRESP_APPL_ID := apps.fnd_profile.value(200); -- AP --('RESP_APPL_ID');
-- vRESP_ID := apps.fnd_profile.value(20639); -- 20639 for payables mgr. for rwjf_payables Mgr (50001); --('RESP_ID');
-- vUSER_ID := apps.fnd_profile.value(1247); -- 1247 for sury 1065 for interface -- ('USER_ID');
LoadToAp := 0;
SELECT COUNT(*)
INTO LoadToAp
FROM rwjf.RWJF_PimsTxnBatchDtl
WHERE GL_OR_AP = 'A'
AND pims_txn_batch_id = :NEW.Pims_Txn_Batch_id;
LoadToGl := 0;
SELECT COUNT(*)
INTO LoadToGl
FROM rwjf.RWJF_PimsTxnBatchDtl
WHERE GL_OR_AP = 'G'
AND pims_txn_batch_id = :NEW.Pims_Txn_Batch_id;
IF LoadToAp > 0 THEN
vRESP_APPL_ID := 200; -- Application Id 200 Account payables
vRESP_ID := 50001; -- RWJF_Payables Mgr for user interface
vUSER_ID := 1065; -- user id for user name interface
apps.fnd_global.apps_initialize(vUSER_ID,vRESP_ID,vRESP_APPL_ID);
ConcReqID := 0;
ReturnCode := FND_REQUEST.SET_MODE(TRUE);
ConcReqID := FND_REQUEST.SUBMIT_REQUEST('RWJF',
'RWJF_PIMS_INT',
'', '', FALSE,
:NEW.Pims_Txn_Batch_id,'AP', chr(0),
END IF;
IF LoadToGl > 0 THEN
vRESP_APPL_ID := 20003;
vRESP_ID := 50003;
vUSER_ID := 1065;
apps.fnd_global.apps_initialize(vUSER_ID,vRESP_ID,vRESP_APPL_ID);
ConcReqID := 0;
ReturnCode := FND_REQUEST.SET_MODE(TRUE);
ConcReqID := FND_REQUEST.SUBMIT_REQUEST('RWJF',
'RWJF_PIMS_INT',
'', '', FALSE,
:NEW.Pims_Txn_Batch_id,'GL',chr(0),
END IF;
insert into test_pims
values
('Test3',:New.Pims_Txn_Batch_id,vUSER_ID,vRESP_ID,vRESP_APPL_ID);
insert into test_pims
values
('Test3',ConcReqID,vUSER_ID,vRESP_ID,vRESP_APPL_ID);
IF ConcReqID = 0 THEN
DBMS_OUTPUT.PUT_LINE('Problem Submitting Program to get pims txn batch'); /* Handle Error */
END IF;
End;
-- End of DDL Script for Trigger APPS.RWJF_PIMS_ORACLE_INTdon't quite understand the structure of your tables but it sounds similiar to a merge statement.
(contiditonally insert, update records depending on whether or not corresponding records exist)
create table custom_table
(cust_no number,
line_no number,
party_id number
create table hz_parties
as (
select 1 party_id, 'A' bill_to_location, 10 cust_no, 100 line_no from dual union
select 2, 'B', 20, 200 from dual union
select 3, 'C', 30, 300 from dual union
select 4, 'D', 40, 400 from dual
merge into custom_table t1
using (select * from hz_parties) t2
on (t1.party_id = t2.party_id)
when not matched then insert (t1.cust_no, t1.line_no, t1.party_id)
values (t2.cust_no, t2.line_no, t2.party_id);
Edited by: pollywog on Mar 5, 2010 6:52 AM -
I am having two table based on insertion on table one i have created trigger , trigger will insert the data to table two
i am getting the error when i execute for the second time i.e i have execute one record each successfully in both tables.
on second time i'm getting this error
CREATE OR REPLACE TRIGGER Triggername
AFTER INSERT ON mytable
DECLARE v_local varchar2(1800);
BEGIN
SELECT col1 INTO v_local FROM myschema.mytab;
insert into mytable (Col1,Col2,Col3)
with t1 as( select v_local str from dual),
t2 as( Select startid, endid from SplitLayout),
t3 as
( select str,startid s,endid e, row_number() over(order by startid) rn from t1,t2)
select * from t3 pivot
max(substr(str,s,e)) str for rn in (1,2,3);
End;
startid,Endid
1,1
2,1
3,1
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "myschema.Triggername", line 4
ORA-04088: error during execution of trigger 'myschema.Triggername'
ORA-06512: at "myschema.SPname", line 4
ORA-06512: at line 1Hi,
eleven less than yesterday. That's good for a start. But keep on tidying up.
Concerning your trigger-problem, "933663" is very right to say
>
you are creating a AFTER INSERT trigger on MYTABLE, which will again insert data into MYTABLE ..!!!!
>
I can't either see why this should be sensible. Do you know the concept of :new and :old. Have a look at
[url http://docs.oracle.com/cd/E11882_01/server.112/e25789/srvrside.htm#CNCPT118]Overview on Triggers. DML-Triggers should interest you most for now.
As far as I understand your first posting the following passage causes the problems
>
SELECT col1 INTO v_local FROM myschema.mytab;to analyze if this statement causes the
>
ORA-01422: exact fetch returns more than requested number of rows
>
you may execute something like
select count (*)
from myschema.mytab
group by col1
having count(*) > 1;Good luck
Bye
stratmo -
Error while firing a trigger After Insert
Dear All
I have created a Table named Punches in user Punch
and I have written a trigger after Insert on table Punches
In that Trigger i am wrting some select Command
and Insert command
tables are located in Other User
while firing the trigger it is showing Error.
pl helpArbar Mehaboob - user553581 wrote:
Dear All
I have created a Table named Punches in user Punch
and I have written a trigger after Insert on table Punches
In that Trigger i am wrting some select Command
and Insert command
tables are located in Other User
while firing the trigger it is showing Error.
pl helpplease provide:
1) your database version
2) the table DDL's
3) some sample data
4) the trigger code
5) the error message you're getting.
without these, it is impossible to suggest an answer. -
How to Create a table with numeric trigger for INSERT
Let me start off by saying that I am very new to DBMS.
I need to create a Table with INSERT Trigger. I am not exactly sure if I need to have a BEFORE ot AFTER insert trigger but leanning towards AFTER.
I have a Java code that will need insert a row each time that piece of code is executed. I would also like an oracle trigger to insert a unique numeric value (REC_ID) for that that record.
I am totally lost and I am not sure how to go about it. Can you point me to the right direction?
Basically my table will have the following 3 columns
REC_ID NUMBER NOT NULL (uniquie value inserted by the trigger)
PROPERTY_NAME VARCHAR2(100 BYTE)
PROPERTY_VAL VARCHAR2(100 BYTE)
Thank you in advance
EricTake a look at the following: Also please do a search in this forum.
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html -
Created a trigger but new values are not inserting in the backup table
I have created a backup table and writter a trigger on a table such that after update old values and new values are to be inserted into the backup table, but new values are not inserting. I am giving the code please help me
create or replace trigger "SUPPQUOTES_AUDIT"
after update or delete on phsuppquotes for each row
begin
insert into phquotes_audit(cprc_new,suppcode,itemcode,cprc_old,negodt,validdt,userid,TRANDATE) values
(:new.cprc,:old.suppcode,:old.itemcode,:old.cprc,:old.negodt,:old.validdt,:old.userid,SYSDATE);
end;old values and new
values are to be inserted into the backup table, butwell you have only one insert there, inserting old values with a new id (which is ok if you don't update the id column, but I don't think that :new is available for deleting ops); you should have two inserts:
insert into
phquotes_audit(cprc_new,suppcode,itemcode,cprc_old,negodt,validdt,userid,TRANDATE) values (:old.cprc,:old.suppcode,:old.itemcode,:old.cprc,:old.negodt,:old.validdt,:old.userid,SYSDATE);
if (updating) then
insert into phquotes_audit(cprc_new,suppcode,itemcode,cprc_old,negodt,validdt,userid,TRANDATE) values (:new.cprc,:new.suppcode,:new.itemcode,:new.cprc,:new.negodt,:new.validdt,:new.userid,SYSDATE);
end if;
gojko adzic
http://gojko.net -
Which trigger to use for insert data into db table in Forms
Hi,
My form is current having a database block with table reference. When enter data into form field and click on save button. Automatically the record is inserted into database table.
I want to make this as manual insert. I changed the data block to a non-database. Where should i write the insert statement in order to insert data into table.
Is it Key-commit trigger at form level?
Please advise.
Thanks,
Yuvaraaj.Hi Yuvaraaj.
Insert should happen when we click on the save which is inbuilt in the form. In this case where should i write the insert statement.Forms in built save commit's the form data where block is based on database not non database.
@2nd reply
Ypu are right. The reason i chnaged the database block to non-database is Currently i have a database block with form field canvas which insert only 1 record in to >table when we click on standard save button. The requirement was to add a field called CHANNEL which should have multiple values displayed. (i created this channel >field in a seperate datablock (non database) and used the same canvas.) When we insert data in all fields (single record) and channel we should be able to selected >multiple channel (say A,B and C) when we click on save then 3 records should be inserted in to the table which looping values for each channel. This was the actual >requirement and this is the reason why iam changing the block to non-database block.You are talking about two blocks.. 1. Master block and 2. Details block name channel
You are inserting one record in master block then insert 3 record name A,B,C for that master record.
Now you want master record should insert to each A,B,C record. Means
'how are you' --master record
and you want
'A'- 'how are you'
'B'- 'how are you'
'C'- 'how are you'OR
?Ok. If you want master record save in database and then want to save non-database(channel) data into database USE Post-Insert trigger at block level and do the rest.
Hope this helps...
Hamid
Mark correct/helpful to help others to get right answer(s).*
Edited by: HamidHelal on Jan 26, 2013 1:20 AM -
Need help with create trigger based on more then 1 table and join.
Hello,
Here i have 3 tables
1. Employee
PERSON_ID
1
1
N
NUMBER
None
ORG_ID
2
N
NUMBER
Frequency
LOC_ID
3
N
NUMBER
Frequency
JOB_ID
4
Y
NUMBER
Height Balanced
FLSA_STATUS_ID
5
Y
NUMBER
Frequency
FULL_NAME
6
N
VARCHAR2 (250 Byte)
Height Balanced
FIRST_NAME
7
N
VARCHAR2 (20 Byte)
Height Balanced
MIDDLE_NAME
8
Y
VARCHAR2 (60 Byte)
Height Balanced
LAST_NAME
9
N
VARCHAR2 (40 Byte)
Height Balanced
PREFERRED_NAME
10
Y
VARCHAR2 (80 Byte)
None
EMAIL
11
Y
VARCHAR2 (250 Byte)
None
MAILSTOP
12
Y
VARCHAR2 (100 Byte)
None
HIRE_DATE
13
N
DATE
None
2. ems_candidate
EMS_CANDIDATE_ID
1
1
N
NUMBER
None
EMS_JOB_ID
2
Y
NUMBER
Frequency
NAME
3
N
VARCHAR2 (255 Byte)
Frequency
EMAIL
4
Y
VARCHAR2 (255 Byte)
None
TELEPHONE
5
Y
VARCHAR2 (25 Byte)
None
EMS_SOURCE_ID
6
Y
NUMBER
Frequency
RECEIVED_DATE
7
Y
DATE
Frequency
COMMENTS
8
Y
VARCHAR2 (4000 Byte)
None
3. employee_resources
EMP_RES_ID
1
1
N
NUMBER
None
PERSON_ID
2
Y
NUMBER
Height Balanced
CANDIDATE_ID
3
Y
NUMBER
Frequency
EMP_START_DATE
4
Y
DATE
None
CUSTOM_RESOURCE_FLAG
5
Y
NUMBER (1)
None
RESOURCE_GROUP_ID
6
N
NUMBER
Frequency
RESOURCE_STATUS_ID
7
N
NUMBER
Frequency
GROUP_LOC_ID
8
N
NUMBER
Height Balanced
ASSIGNED_JIRA
9
Y
VARCHAR2 (250 Byte)
None
REVOKED_JIRA
10
Y
VARCHAR2 (250 Byte)
None
CREATED_DATE
11
Y
DATE
SYSDATE
None
UPDATED_DATE
12
Y
DATE
None
Now i want to create trigger when new record get inserted in employee table wanted to update person_id in employee_resources table.
So i want to match ems_candidate.name with employee.full_name , ems_candidate.ems_job_id with employee.ems_job_id. And if it matched then update person_id in employee_resources table else through an exception and insert record in temp table.
If anybody has an idea can u please help me.
Thanks,
Gayatri.I created below trigger
CREATE TRIGGER emp_resources_upd_person_id
AFTER INSERT ON ems.employee
FOR EACH ROW
BEGIN
UPDATE ems.employee_resources
SET person_id = :new.person_id
WHERE candidate_id = (SELECT ems_candidate_id
FROM ems.ems_candidate cand, ems.employee emp
WHERE TRIM(UPPER(emp.first_name)) = TRIM(UPPER(SUBSTR (cand.name, 1, INSTR (cand.name, ' ') - 1)))
AND TRIM(UPPER(emp.last_name)) = TRIM(UPPER(SUBSTR (cand.name,INSTR (cand.name, ' ') + 1,DECODE (INSTR (SUBSTR (cand.name, INSTR (cand.name, ' ') + 1), ' '),0,LENGTH (cand.name),(INSTR (SUBSTR (cand.name, INSTR (cand.name, ' ') + 1), ' ') - 1)))))
AND emp.person_id = :new.person_id);
EXCEPTION
WHEN OTHERS THEN
INSERT INTO ems.update_person_id_exception(person_id,first_name,last_name,full_name) VALUES(:new.person_id,:new.first_name,:new.last_name,:new.full_name);
END;
Now when i am trying to insert row in ems.employee table it gives me an error
ORA-04091
table string.string is mutating, trigger/function may not see it
Cause: A trigger (or a user defined plsql function that is referenced in this statement) attempted to look at (or modify) a table that was in the middle of being modified by the statement which fired it.
Action: Rewrite the trigger (or function) so it does not read that table.
Can anybody please help me to come out from these error.
Thanks,
Gayatri. -
Trigger to copy records from one table to another; ORA-04091:
Hello,
I'm trying to create a trigger that will move data from one table to another.
I have two tables (Trial1, Trial2) Both of them contains the same attributes (code, c_index)
I want to move each new record inserted in (code in Trial1) to (code in Trial2)
This is my trigger:
Create or replace trigger trg_move_to_trial2
After insert on Trial1
for each row
begin
insert into Trial2 (code)
select :new.code from Trial1;
end;It compiled, but when I insert new (code) record into (Trial1) it display this error:
Error report:
SQL Error: ORA-04091: table STU101.TRIAL1 is mutating, trigger/function may not see it
ORA-06512: at "STU101.TRG_MOVE_TO_TRIAL2", line 3
ORA-04088: error during execution of trigger 'STU101.TRG_MOVE_TO_TRIAL2'
04091. 00000 - "table %s.%s is mutating, trigger/function may not see it"
*Cause: A trigger (or a user defined plsql function that is referenced in
this statement) attempted to look at (or modify) a table that was
in the middle of being modified by the statement which fired it.
*Action: Rewrite the trigger (or function) so it does not read that table.I know what does this error mean, but I don't how to fix the error.
I tried to change the (After insert on Trial1) to be (Before insert on Trial1); that worked, but not in the right way. When I insert new value into (code in Trial1) and refreshed Trial2 table, as much as records I have in Trial 2 they will be duplicated. E.g.
Trial2
code
111
222
333when I insert in Trial1
Trial1
code
444
Trial2 will be:
code
111
222
333
444
444
444Can you please tell me how to solve this issue?
Regards,
Edited by: 1002059 on Apr 23, 2013 5:36 PMYou should not select from Trial1 - you have the data already. Just insert that value.
Create or replace trigger trg_move_to_trial2
After insert on Trial1
for each row
begin
insert into Trial2 (code)
values (:new.code);
end; regards,
David -
Consult last insert id in a table with EJBQL
How can I consult the last insert id in a table using EJBQL?
I need to find a sentence like select last_insert_id()
ThanksHi
If the trigger is on the table, then it will be fired when an INSERT takes place, you don't need to code for it specially.
Do lovely SQL> CREATE TABLE insert_test
(col1 NUMBER,
col2 VARCHAR(2));
Table created.
Elapsed: 00:00:00.24
Do lovely SQL> CREATE SEQUENCE insert_seq
START WITH 1
MAXVALUE 999999999999999999999999999
MINVALUE 1;
Sequence created.
Elapsed: 00:00:00.00
Do lovely SQL> CREATE TRIGGER insert_trig
BEFORE INSERT ON insert_test
FOR EACH ROW
DECLARE
L_ID NUMBER;
BEGIN
SELECT insert_seq.NEXTVAL INTO L_ID FROM DUAL;
IF :NEW.col1 IS NULL THEN
:NEW.col1 := L_ID;
END IF;
END;
Trigger created.
Elapsed: 00:00:00.23
Do lovely SQL> INSERT INTO insert_test (col2) VALUES('TT');
1 row created.
Elapsed: 00:00:00.03
Do lovely SQL> COMMIT;
Commit complete.
Elapsed: 00:00:00.00
Do lovely SQL> SELECT * FROM insert_test;
COL1 CO
1 TT
Elapsed: 00:00:00.04See - you just need to do the insert.
Cheers
Ben -
Inserts into Global Temporary Table
I'm working on using a global temporary table in one of my apps. I have a small test run here to isolate the problem. It simply creates the global temporary table, inserts a row, commits and then does a select to see if the insert worked. No data shows in the table when running this. I don't know much about global temp tables, so any help would be appreciated.
CREATE GLOBAL TEMPORARY TABLE AGENT_SILO.AS_TEMP_VALIDATE (
SBI_EMPLOYEE_ID NUMBER,
CURRENT_FLAG char(1),
EFFECTIVE_START date,
EFFECTIVE_END date
) ON COMMIT DELETE ROWS;
INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
VALUES(0, '', SYSDATE, SYSDATE);
commit;
SELECT * FROM AGENT_SILO.AS_TEMP_VALIDATE;So I wonder what else I'm doing wrong that's really obvious. Here's what i'm trying to accomplish and maybe there's a better way of going about it.
I have a trigger that is supposed to do some validation before the insert is allowed to go through. So here's my approach. I have a trigger fired when there's an insert into the AS_Employee_history table. This passes some of the fields from this insert into a proc (the id, a flag and a couple of dates). Within the proc, i create a global temp table, insert these passed values into the temp table. Then I have a cursor to basically copy the rows from the as_employee_history table that have the same id. Then I can do some selects on the temp table to see if it passes the validation.
I have outputs throughout for debugging and it gets to right after the inserts into the temp table, then the rest of the code doesn't appear to be executed. So it looks like it's failing at the execution of select statements on the temp table. Anything else obvious that I"m missing here?
Here's my proc.
PROCEDURE "PAS_VALIDATE" (STATUS OUT VARCHAR2, v_status OUT BOOLEAN, NEW_SBI_EMPLOYEE_ID IN NUMBER,
NEW_CURRENT_FLAG IN CHAR, NEW_EFFECTIVE_START IN DATE,
NEW_EFFECTIVE_END IN DATE)
IS
v_prev_effective_end date;
v_flag_count number;
v_flag_count_date number;
--variables to store dynamic sql returns
v_sql_flag_count_date varchar2(255);
v_sql_flag_count varchar2(255);
v_sql_prev_eff_end varchar2(255);
cursor c_row is
select * from AGENT_SILO.AS_EMPLOYEE_HISTORY EMP
where (EMP.SBI_EMPLOYEE_ID = NEW_SBI_EMPLOYEE_ID);
r_row c_row%ROWTYPE;
BEGIN
Status := 'Started';
v_status := true;
DBMS_OUTPUT.PUT_LINE('Creating temporary table...');
execute immediate 'CREATE GLOBAL TEMPORARY TABLE AGENT_SILO.AS_TEMP_VALIDATE (
SBI_EMPLOYEE_ID NUMBER,
CURRENT_FLAG char(1),
EFFECTIVE_START date,
EFFECTIVE_END date
) ON COMMIT PRESERVE ROWS';
DBMS_OUTPUT.PUT_LINE('Validating the data...');
--DBMS_OUTPUT.PUT_LINE('Inserting submitted row into temp table');
--Insert the new row being submitted from user into the temp table
execute immediate 'INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
VALUES(' || NEW_SBI_EMPLOYEE_ID || ',
''' || NEW_CURRENT_FLAG || ''',
to_date(''' || to_char(NEW_EFFECTIVE_START, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''),
to_date(''' || to_char(NEW_EFFECTIVE_END, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''))';
--Insert the other rows to we end up with a subset of the employee history table
--with only rows that match the sbi_employee_id of the submitted row
--DBMS_OUTPUT.PUT_LINE('Inserting into temp table...');
open c_row;
loop
fetch c_row into r_row;
exit when c_row%NOTFOUND;
execute immediate 'INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
VALUES(' || r_row.SBI_EMPLOYEE_ID || ',
''' || r_row.CURRENT_FLAG || ''',
to_date(''' || to_char(r_row.EFFECTIVE_START, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''),
to_date(''' || to_char(r_row.EFFECTIVE_END, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''))';
end loop;
close c_row;
DBMS_OUTPUT.PUT_LINE('After inserts');
-----Store queries to determine values for validation--------------------------
v_sql_prev_eff_end := 'SELECT to_char(max(effective_end), ''dd-mon-yy'')
FROM AGENT_SILO.AS_TEMP_VALIDATE
where to_char(EFFECTIVE_END, ''dd-mon-yy'') != ''31-dec-99'' AND
SBI_EMPLOYEE_ID = NEW_SBI_EMPLOYEE_ID';
--Find the largest effective_end, besides the 9999 value
execute immediate v_sql_prev_eff_end into v_prev_effective_end;
DBMS_OUTPUT.PUT_LINE('The highest previous end date: ' || v_prev_effective_end);
--...........Validation testing...........
execute immediate 'DROP TABLE AGENT_SILO.AS_TEMP_VALIDATE'; --Drop temp table
DBMS_OUTPUT.PUT_LINE('Validation Procedure Complete');
COMMIT;
status:='Success';
EXCEPTION
When Others Then
ROLLBACK;
Status := SQLERRM;
END;
Thanks a bunch for helping a noob out. -
I wish to insert data into a table only when the value of the inserted data has changed. Thus, in a time series, if the value of the data at time, t-1, is 206 then if the data to be inserted at time t is 206, then it is skipped (not entered).
If the value of the data at time t+1 is 206, it is skipped also; until the value changes, so if the value at t+1 was 205, then that would be inserted, and if at time t+2 the data is 206, it would be inserted too.
What is the best way to do it without increasing overheads?This view works:
SELECT
i.IDNO,i.[Date],i.[Level]
FROM
mytable i
INNER
JOIN mytable
d
ON
d.IDNO
= i.IDNO-1
WHERE
i.[Level]
<> d.[Level]
on this mytable below. A trigger could be quite useful here although I am cautious using them. However I wish to avoid the overhead by not having a temp table (which could be sizable). mytable below
should give 3 lines. The IDNO is an identity column.
IDNO
Item
Date
Level
1
X24
12/23/13 10:41
22996
2
X24
12/23/13 10:41
22996
3
X24
12/23/13 9:21
23256
4
X24
12/23/13 9:21
23256
5
X24
12/23/13 9:22
23256
6
X24
12/23/13 9:22
23256
7
X24
12/23/13 9:22
22916 -
How to insert into two differents tables at the same time
Hi
I'm newer using JDev, (version 3.1.1.2 cause the OAS seems to support just the JSP 1.0)
and I want to insert into two differents tables at the same time using one view.
How can I do that ?
TIA
EdgarOracle 8i supports 'INSTEAD OF' triggers on object views so you could use a process similar to the following:
1. Create an object view that joins your two tables. 'CREATE OR REPLACE VIEW test AS SELECT d.deptno, d.deptname, e.empname FROM DEPT d, EMP E'.
2. Create an INSTEAD OF trigger on the view.
3. Put code in the trigger that looks at the :NEW values being processed and determines which columns should be used to INSERT or UPDATE for each table. Crude pseudo-code might be:
IF :NEW.deptno NOT IN (SELECT deptno FROM DEPT) THEN
INSERT INTO dept VALUES(:NEW.deptno, :NEW.deptname);
INSERT INTO emp VALUES (:NEW.deptno, :NEW.empname);
ELSE
IF :NEW.deptname IS NOT NULL THEN
UPDATE dept SET deptname = :NEW.deptname
WHERE deptno = :NEW.deptno;
END IF;
IF :NEW.empname IS NOT NULL THEN
UPDATE emp SET empname = :NEW.empname
WHERE deptno = :NEW.deptno;
Try something along those lines.
null -
INSTEAD OF trigger on view to update a table. error in 4.2apex tabular rpt
I have created a view (LANDINGS_VIEW') that I am hoping to use to add/modify data over several tables. I am using INSTEAD OF trigger to update/insert into the underlying tables. I am receiving the error:
•ORA-01858: a non-numeric character was found where a numeric was expected ORA-06512: at "SAFIS.LANDINGS_V_IO_UPD_TRG", line 4 ORA-04088: error during execution of trigger 'SAFIS.LANDINGS_V_IO_UPD_TRG' (Row 1)I am only setting PRICE = 300.
any thoughts? Am I setting this up propertly? thanks for your help!!
Karen
The LANDING_VIEW is set up as follows:
-- Start of DDL Script for View SAFIS.LANDINGS_VIEW
-- Generated 03-May-2013 10:25:38 from [email protected]
CREATE OR REPLACE VIEW landings_view (
landing_seq,
dealer_rpt_id,
unit_measure,
reported_quantity,
landed_pounds,
dollars,
disposition_code,
grade_code,
species_itis,
market_code,
price,
area_fished,
sub_area_fished,
lease_num,
gear_code,
de,
ue,
dc,
uc,
local_area_code,
fins_attached,
explanation,
late_report,
modified_data,
nature_of_sale,
hms_area_code,
sale_price,
deleted )
AS
select l.LANDING_SEQ,
l.DEALER_RPT_ID,
l.UNIT_MEASURE,
l.REPORTED_QUANTITY,
l.LANDED_POUNDS,
l.DOLLARS,
l.DISPOSITION_CODE,
l.GRADE_CODE,
l.SPECIES_ITIS,
l.MARKET_CODE,
l.PRICE,
l.AREA_FISHED,
l.SUB_AREA_FISHED,
l.LEASE_NUM,
l.GEAR_CODE,
l.DE,
l.UE,
l.DC,
l.UC,
l.LOCAL_AREA_CODE,
a.fins_attached,
a.explanation,
a.late_report,
a.modified_data,
a.nature_of_sale,
a.hms_area_code,
a.sale_price,
a.deleted
from landings l,
landings_hms a
where l.dealer_rpt_id = v('P110_DEALER_RPT_ID') and
l.dealer_rpt_id = a.dealer_rpt_id(+) and
l.landing_seq = a.landing_seq(+)
-- Triggers for LANDINGS_VIEW
CREATE OR REPLACE TRIGGER landings_v_io_upd_trg
INSTEAD OF
UPDATE
ON landings_view
REFERENCING NEW AS NEW OLD AS OLD
DECLARE
v_first_day date;
BEGIN
update landings set landing_seq = :old.landing_seq,
dealer_rpt_id = :old.dealer_rpt_id,
unit_measure = :new.unit_measure,
reported_quantity = :new.reported_quantity,
-- landed_pounds = :new.landed_pounds,
dollars = :new.dollars,
disposition_code= :new.disposition_code,
grade_code = :new.grade_code,
species_itis = :new.species_itis,
market_code = :new.market_code,
price = :new.price,
area_fished = :new.area_fished,
sub_area_fished = :new.sub_area_fished,
-- lease_num = :new.lease_num,
gear_code = :new.gear_code,
de = :new.de,
ue = :new.ue,
dc = :new.ue,
uc = :new.uc,
local_area_code = :new.local_area_code ;
/* update landings_hms set dealer_rpt_id = :old.dealer_rpt_id,
landing_seq = :old.landing_seq,
fins_attached = :new.fins_attached,
explanation = :new.explanation,
late_report = :new.late_report,
modified_data = :new.modified_data,
nature_of_sale = :new.nature_of_sale,
hms_area_code = :new.hms_area_code,
sale_price = :new.sale_price,
de = sysdate,
ue = :new.ue,
dc = :new.dc,
uc = :new.uc ;
end;
-- End of DDL Script for Trigger SAFIS.LANDINGS_KEH_V_IO_TRG
CREATE OR REPLACE TRIGGER landings_v_io_trg
INSTEAD OF
INSERT
ON landings_view
REFERENCING NEW AS NEW OLD AS OLD
DECLARE
v_first_day date;
BEGIN
insert into landings_keh (landing_seq,
dealer_rpt_id,
unit_measure,
reported_quantity,
landed_pounds,
dollars,
disposition_code,
grade_code,
species_itis,
market_code,
price,
area_fished,
sub_area_fished,
lease_num,
gear_code,
de,
ue,
dc,
uc,
local_area_code)
values ( landings_seq.NEXTVAL,
:new.dealer_rpt_id,
:new.unit_measure,
:new.reported_quantity,
:new.landed_pounds,
:new.dollars,
:new.disposition_code,
:new.grade_code,
:new.species_itis,
:new.market_code,
:new.price,
:new.area_fished,
:new.sub_area_fished,
:new.lease_num,
:new.gear_code,
sysdate,
:new.ue,
:new.dc,
:new.uc,
:new.local_area_code) ;
insert into landings_hms (dealer_rpt_id,
landing_seq,
fins_attached,
explanation,
late_report,
modified_data,
nature_of_sale,
hms_area_code,
sale_price,
de,
ue,
dc,
uc,
deleted)
values (:new.dealer_rpt_id,
landings_seq.CURRVAL,
:new.fins_attached,
:new.explanation,
:new.late_report,
:new.modified_data,
:new.nature_of_sale,
:new.hms_area_code,
:new.sale_price,
sysdate,
:new.ue,
:new.dc,
:new.uc,
:new.deleted);
end;
-- End of DDL Script for Trigger SAFIS.LANDINGS_KEH_V_IO_TRG
-- End of DDL Script for View SAFIS.LANDINGS_VIEWbtw, I have succefully run the following update in sqlplus.
update landings set landing_seq = 8604583,
dealer_rpt_id = 2660038,
unit_measure = 'LB',
reported_quantity = 3,
-- landed_pounds = :new.landed_pounds,
dollars = 900,
disposition_code= '001',
grade_code = '10',
species_itis = '160200',
market_code = 'UN',
price = 30,
area_fished = null,
sub_area_fished =null,
-- lease_num = :new.lease_num,
gear_code = '050',
de = sysdate,
ue = 'keh',
dc = null,
uc = 'keh',
local_area_code = null
where landing_seq = 8604583; I am using apex 4.2
Edited by: KarenH on May 3, 2013 10:29 AM
Edited by: KarenH on May 3, 2013 10:31 AM
Edited by: KarenH on May 3, 2013 11:04 AM
Edited by: KarenH on May 3, 2013 4:09 PMcould it be so simple?
when I created the tabular form on my view, LANDINGS_VIEW, the APPLYmru was automatically generated, referencing the view name LANDINGS_VIEW. I modified that to indicate the table name (LANDINGS). I am not certain why that would work, but it seems to so far.
this post was helpful: Re: instead of trigger on view
I am now testing to make certain both the underlying tables can be updated, LANDINGS and LANDINGS_HMS
Maybe you are looking for
-
I have the iphone 3gs. I enter a calendar appointment and utilize the alert feature with that appointment. the next day the appointment is still there but the alert is no longer there. is this an issue because I back up to the icloud or is there a s
-
Local disks are in FAIL status after installing the cluster
The /var/adm/messages log isn't giving me much info to go on. This has happened twice now. After installing the cluster, my local disks are in a FAIL status and the cluster is not giving me much information why. It's a two-node cluster w/ x2100 M2s.
-
Deskjet D2666 won't work properly on WIndows 7
Hello, I have just bought a HP Deskjet D2666 printer, and i have problems when i trying to print on my PC. My PC is running windows 7 32 bit. I have already try the solution that was offered from the HP website, installing the windows 7 proper driver
-
How to: time capsule 4G working without ethernet wire
HI, I m a french user, i don t found an official french community... So i use it in english with my bad language :/ appologies for that! I ll try to explained you my problem. When i call the apple chat hotline to have more informations about TC, he s
-
Can not close web page out since upgrading IOS 8
Can not close web page out since upgrading IOS 8