Need to create a trigger that generates multiple rows in another table
{size: 12} HelloI use Oracle9i (9.2.0.4.0)
My problem is:
I need to create a trigger that create different in the other table lines when someone will introduce a new line in the first table.
For this, I use the table 4:
1. first one where you want the trigger.
2. a second just to take information.
3. a third to make a trip meter.
4. the fourth is the table where I want to create new lines. {size}
Here is a summary of these 4 tables:
{color: blue} Table 1
STOJOU
Number ¿Nulo? Tipo
STOFCY_0 NOT NULL VARCHAR2 (9)
ITMREF_0 NOT NULL VARCHAR2 (60)
LOT_0 NOT NULL VARCHAR2 (45)
VCRTYP_0 NOT NULL NUMBER (3)
VCRNUM_0 NOT NULL VARCHAR2 (45)
VCRLIN_0 NOT NULL NUMBER (10)
QTYSTU_0 NOT NULL NUMBER
NUMVCR_0 NOT NULL VARCHAR2 (45) {color}
{color: blue} Table 2
ITMMASTER
Number ¿Nulo? Tipo
ITMREF_0 NOT NULL VARCHAR2 (60)
ZCOEFI_0 NOT NULL NUMBER {color}
{color: blue} Table 3
ZCTUART;
Number ¿Nulo? Tipo
CTUART_0 NOT NULL NUMBER (10)
CTUDATE_0 NON NULL DATE {color}
{color: blue} Table 4
ZUART
Number ¿Nulo? Tipo
ZUARTDM_0 NOT NULL VARCHAR2 (102)
STOFCY_0 NOT NULL VARCHAR2 (9)
STOCOU_0 NOT NULL NUMBER
ITMREF_0 NOT NULL VARCHAR2 (60)
LOT_0 NOT NULL VARCHAR2 (45)
CREDAT_0 NOT NULL DATE
QTYSTU_0 NOT NULL NUMBER
STA_0 NOT NULL VARCHAR2 (3)
VCRLIN_0 NOT NULL NUMBER (10)
VCRNUM_0 NOT NULL VARCHAR2 (45)
VCRTYP_0 NOT NULL NUMBER (3) {color}
I do this trigger:
CREATE OR REPLACE TRIGGER CREA_REGISTROS_TRAZA
AFTER INSERT ON STOJOU
FOR EACH ROW
DECLARE
n INTEGER;
ct NUMBER;
fecha_actual VARCHAR2;
fecha_old VARCHAR2;
codigo_dm VARCHAR2;
BEGIN
fecha_actual := TO_CHAR(SYSDATE, 'DD/MM/YYYY');
-- SELECT TO_CHAR(sysdate, 'DD/MM/YYYY') INTO fecha_actual FROM DUAL;
SELECT TRUNC((STOJOU.QTYSTU_0/ITMMASTER.ZCOEFI_0),0) INTO n FROM STOJOU INNER JOIN ITMMASTER ON STOJOU.ITMREF = ITMMASTER.ITMREF;
FOR i IN 1 .. n
LOOP
SELECT CTUART_0,TO_CHAR(CTUDAT_0, 'DD/MM/YYYY') INTO ct,fecha_old FROM ZCTUART;
IF fecha_old <> fecha_actual THEN
ct := 0;
END IF;
ct := ct + 1;
INSERT INTO ZCTUART
(CTUART_0,CTUDAT_0)
VALUES
(ct,SYSDATE);
codigo_dm := SUBSTR('000000000000000000000',1,20 - LENGHT(NEW.ITMREF_0)) || NEW.ITMREF_0 || SUBSTR('0000000000',1,10 - LENGHT(NEW.LOT)) || NEW.LOT || SUBSTR('0000',1,4 - LENGHT(ct)) || ct;
INSERT INTO ZUART
(ZUARTDM_0,ITMREF_0,CREDAT_0,STA_0,QTYSTU_0,LOT_0,STOFCY_0,VCRLIN_0,VCRNUM_0,VCRTYP_0)
VALUES
(codigo_dm,NEW.ITMREF_0,SYSDATE,0,NEW.QTYSTU_0,NEW.LOT_0,NEW.STOFCY_0,NEW.VCRLIN_0,NEW.VCRNUM_0,NEW.VCRTYP_0);
END LOOP;
END CREA_REGISTROS_TRAZA;
/
{size: 12} And the error message I get States is just:"The trigger was created with compilation errors."
Thanks for the help {size}
You must prefix your NEW "columns" with a colon, as in: NEW.
Tags: Database
Similar Questions
-
Update trigger that inserts the record in another table
I searched the forum and the web for an example like this and I can not find a:
A field is updated in the TABLE_A and it triggers a single record TABLE_B insert that has the old and the new value of the field.
I write a lot of complex data warehouse SQL-based reports, but very rarely do much PL/SQL, any help would be appreciated.
Thanks in advance.Hello
You can specify that the trigger should fire only when certain columns are referenced, like this:
create or replace trigger test_fund_trig before update OF FUNDING on table_a ...
If you do this, the trigger will not draw on statements such as:
UPDATE table_a SET mod_date = SYSDATE;
You should always use an IF statement, as I mentioned earlier, if you do not want to follow the updates where the value of this column has not really changed.
-
inserting multiple rows of another table with incremented recordid
Hi all
I HAVE TWO TABLES:
CREATE TABLE TEMP_TEST1)
NUMBER OF RECID,
TESTCHAR VARCHAR2 (500)
)
AND
CREATE TABLE TEMP_TEST2)
TESTCHAR VARCHAR2 (500)
)
Both the table contains data in it. I want to insert data from TEMP_TEST2 in TEMP_TEST1 with RECID incremented for each record, which must be greater than max (RECID) of TEMP_TEST1.
PS: I have to query insert only, I cannot make changes in the structure of table or RECID of TEMP_TEST1 is not automatically incremented.
Please suggest a query that selects the record of TEMP_TEST2 and TEMP_TEST1 insert with recid incremented for each record.
Thank you.SQL> insert into TEMP_TEST2(TESTCHAR) 2 select 'Test'||level from dual connect by level < 10 3 / 9 rows created. SQL> SQL> SQL> insert into TEMP_TEST1(RECID,TESTCHAR) 2 select (select nvl(max(RECID),0) from TEMP_TEST1) + rownum, t2.TESTCHAR 3 from TEMP_TEST2 t2 4 / 9 rows created. SQL> SQL> select * from TEMP_TEST1 2 / RECID TESTCHAR ---------- ---------- 1 Test1 2 Test2 3 Test3 4 Test4 5 Test5 6 Test6 7 Test7 8 Test8 9 Test9 9 rows selected. SQL> insert into TEMP_TEST1(RECID,TESTCHAR) 2 select (select nvl(max(RECID),0) from TEMP_TEST1) + rownum, t2.TESTCHAR 3 from TEMP_TEST2 t2 4 / 9 rows created. SQL> SQL> select * from TEMP_TEST1 2 / RECID TESTCHAR ---------- ---------- 1 Test1 2 Test2 3 Test3 4 Test4 5 Test5 6 Test6 7 Test7 8 Test8 9 Test9 10 Test1 11 Test2 RECID TESTCHAR ---------- ---------- 12 Test3 13 Test4 14 Test5 15 Test6 16 Test7 17 Test8 18 Test9 18 rows selected. SQL>
Good bye
DPT -
Trying to create a trigger that adds a value to a field based on another field
Hello
Im trying to set a trigger that will add a field to a table if another field = the same thing and one where the condition is met, but can't seem to get anything to do and can't find anything online suggesting the syntax.
the use of im tables are
Applications_History
Students
I need the trigger to identify if the 'status' field = applicant accepted when a new data column is added, if that is the case I need to identify the scope of student_number of applications_history and match it to the student_number on students field, I then need to add a 'Y' in the field 'put' corresponding to this student in the student table. I'm looking for without stopping for some type of syntax format online but could not find anything, is it still possible?
Thank you
Something like that?
create or replace trigger aiur_applications_history
after insert or update on applications_history
for each line
Start
If nvl (: old.application_status, 'x'). = 'candidate admitted '.
and: new.application_status = 'candidate admitted '.
then
students update
the value = 'y '.
where student_number =: new.student_number;
end if;
end;
/
Kind regards
Zlatko
-
How to create a sequence that generates in the form of intellectual property?
Hello
I want to create a sequence that can generate an IP numbers. as
224.0.0.1
224.0.0.2
.
.
.
224.255.255.255
Is this possible?
Thank you very muchKinsaKaUy? wrote:
Then, just the format of address IP (exercise left to you)
Hint please :)
Enter the socket interface ntoa - simple enough to reproduce in the SQL and PL/SQL.
PS. Look in the section "+ dotted IP number +"-it should run to the top of implementation details.
-
need to create a user with read-only access only two tables
I am trying to create a user who has access to only two tables in a table space. Please tell me what privileges required and I need to go read on this two tables
Best regards
AtiqGRANT SELECT ON SCHEMA.TABLENAME TO USERNAME;
-
Update multiple rows in a table at a time
Hi all
I write a stored procedure that fills all columns in a table, that table with a query with the exception of a single column, say 'ABC' column in this table. I have to load this left on column using a different query that refers to some other tables. How can I update this column 'ABC' with all its rows of data from a different query?
Thank you very much!!If you post an update with a create table and insert statements, it would be useful... I think that you want to update a table with a select from another table using a join... is that correct?
c customer update
Set client_name =)
Select client_name
of another_customer_table one
where a.customer_id = c.customer_id_from_original_customer_table
)
where c.customer_id in (select customer_id from another_customer_table)Where clause is required only if you don't want to update missing customer_ids to null.
-
How to insert multiple rows in a table by the user (pl/sql)
Hello
I was trying to insert several rows in a table by a user by some pl/sql, but not every time entry. :/
What is happening is that the program requires each time ask the user for the new value but the loop
1 values inserts actually four times (the loop is run four times). can any point on what I am
doing wrong or solutions will be fun ;)
what I wrote here
---------------------------------
Set serveroutput on
set verify off
declare
EmpNo number;
EmpName varchar2 (20);
Start
because loop me in 1.4
EmpNo: = & empno;
EmpName: = '& empname';
insert into values(empno,empname) of the employee;
end loop;
end;
-------------------------------
do not laugh at my code, I'm new to this oracle :D
Thank you, prospects for the future for a responseuser13371438 wrote:
Thanks for the info, looks like a nice tool will ;) try
but I really want (my problem) in pl/sqlTake a quick re-read my post above.
PL/SQL is a process running on the database server. This process cannot interact with the client computer. He can't ask for user input, and it cannot display the output to the client. Client interface tools can only do. You are eager to get feedback from a user, if you need an interface tool to do. SQL * Plus can interface and application of entry, but only as variable substition, and it does not really provide a programming construct that allows you to run a program in a loop to do. Do this using SQL * Plus you must pair it with shell/dos scripting languages, but more ideally you should use an interface appropriate as Apex.
I was wondering if it all works in pl/sql to release cached data (as fflush (stdin) in c ++)
PL/SQL does not a customer entry, so there is no sense to have something to release the cached data. You pass the values of PL/SQL code using procedures or functions with parameters.
-
Delete multiple rows in the table.
How to remove several rows in the table at the same time?
I have a table with 10 rows.
I have a loop for delete lines 1, 3 and 6.
It deletes the row 1 and 3 of the Index out of Bounds exception.
I know why this is happening.
I'm looking for a function or something to delete several lines at once?
Thank you
It must be a logic error.
For each row, you delete, you should reduce the number of indexes.
For example
If you want to delete lines 1, 3 and 6 of a table that contains 6 rows
Remove row1 as Table.Row [0].instanceManager.removeInstance (); [now how many lines will become 5]
Remove row3 as Table.Row [1].instanceManager.removeInstance (); [Note that index is 1 because you have already deleted a record, and the index starts at 0.
Remove row6 as Table.Row [3].instanceManager.removeinstance (); [already two deleted record, so 6-2-1 = 3 is your index to remove]
You understand the logic?
Nith
-
Find columns that exist in one, but that do not exist in another table?
I ' having a slight problem. I can't find an appropriate SQL query to return values for a column that exist in a table, but that do not exist in another (related).
TABLE CAR
(
PK CAR_ID,
CAR_TYPE
)
TABLE CAR_IN_REPAIR
(
PK ID,
FK CAR_ID,
FK REPAIR_SERVICE_ID
RETURN_DATE (NULL)
)
I want to show the records that appear in the table of the CAR, but who are not in the CAR_IN_REPAIR and that CAR_IN_REPAIR. RETURN_DATE is less than SYSDATE or zero (date of return unknown).
In short, I want the query to display the cars that are currenty in repair or does not know the date of return from the repair center (NULL)
I did a SQL query:
SELECT c.id
DRIVE c, CAR_IN_REPAIR r
WHERE c.id NOT IN r.car_id
the query returned no data but data is in the table of the CAR because he displayed when I SELECT * CAR?
Published by: OraNewbie on August 28, 2008 21:02Try this-
strikeselect * from CARminusselect * from CAR_IN_REPAIR--strike--
select * from CAR c WHERE c.id NOT IN ( select r.car_id from CAR_IN_REPAIR r )
Hope this will help you.
Kind regards.
LOULOU
Published by: Satyaki_De on August 29, 2008 12:35 AM
Oops! The table structure is different...
Published by: Satyaki_De on August 29, 2008 12:38 AM
-
Create a trigger that send mail with attachment after insertion of a line in Oracle APEX
I want to create an insert after trigger on a table that is to send a mail with an attachment. Here is my code.
CREATE OR REPLACE TRIGGER tr_feedback
AFTER INSERT on REVIEWS
FOR EACH LINE
DECLARE
l_id NUMBER;
BEGIN
l_id: = APEX_MAIL. SEND)
p_to => ' [email protected] ',
P_FROM = >: NEW. E-mail
p_subj = >: NEW. Object
p_body = > "Please see the attachment."
p_body_html = > ' review of < b > please < /b > the attachment ")
APEX_MAIL. ADD_ATTACHMENT (p_mail_id = > l_id,)
p_attachment = >: NEW. FILE,
p_filename = >: NEW. FILE NAME,
p_mime_type = >: NEW. MIME);
END;
But when I insert data, I get the following error:
ORA-20022: Null value provided for the parameter p_filename.
ORA-06512: at "APEX_040200.WWV_FLOW_MAIL", line 1070
ORA-06512: at "APEX_040200.WWV_FLOW_MAIL_API", line 141
ORA-06512: at "TR_FEEDBACK", line 11
ORA-04088: error during execution of trigger 'TR_FEEDBACK '.
Now, how can I fix that? Thanks in advance.
Agree with the above. Triggers (ab) should not be used in this way. Nontransactional process should not be based on a transactional trigger. These processes are part of the business logic and should be at the level of the company of codification (Summit, you can add a process to be executed once the completed insertion)
-
Need to create the form that the user can fill out and SAVE Reader
Hello
My form, of course, works fine in Adobe Acrobat 4 CS4, is sunk when typed in with Acrobat Reader. It says at the top:
"Please complete the following form. You cannot save data typed into the form. Please print your form if you would like a copy for your records. »
* I know it's possible * to make it writable / recordable for users of readers, because I have a form that someone else created and in Reader the message says: "Please complete the following form. You can save the data entered in the form. »
What setting do I change in Acrobat to make recordable in Reader? Document attached.
Thank you in advance!
Open the PDF in Acro 8 or 9 and in the Advanced menu, choose extend features in Adobe Reader.
-
Need to create a primary key by using sequence in a table with records.
Hello
I want to create a primary key for a table that is already having a huge number of records. Am thinking to create the primary key by using a sequence generator. Could someone tell how can I do this using SQL or PL - SQL.
Kind regards
SKHello
Try this...
SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected. SQL> create sequence emp_empno_seq 2 start with 1 3 minvalue 1 4 maxvalue 999999999999999999999 5 increment by 1 6 nocache 7 noorder 8 nocycle; Sequence created. SQL> SQL> ed Wrote file afiedt.buf 1 update emp 2* set empno=emp_empno_seq.nextval 3 / 14 rows updated. SQL> commit; Commit complete. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 1 SMITH CLERK 7902 17-DEC-80 800 20 2 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 3 WARD SALESMAN 7698 22-FEB-81 1250 500 30 4 JONES MANAGER 7839 02-APR-81 2975 20 5 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 6 BLAKE MANAGER 7839 01-MAY-81 2850 30 7 CLARK MANAGER 7839 09-JUN-81 2450 10 8 SCOTT ANALYST 7566 19-APR-87 3000 20 9 KING PRESIDENT 17-NOV-81 5000 10 10 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 11 ADAMS CLERK 7788 23-MAY-87 1100 20 12 JAMES CLERK 7698 03-DEC-81 950 30 13 FORD ANALYST 7566 03-DEC-81 3000 20 14 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected.
Thank you
Prakash P -
Creating a trigger to run only when a new table is created
I know that I can use this to create the DDL create relaxation.
Problem is that this trigger would run on CFDS as "Create sequence." How can I perform it only for 'Create Table' CFDS?CREATE OR REPLACE TRIGGER create_table_trigger AFTER CREATE ON SCHEMA DECLARE BEGIN END;
Published by: wonderboy87 on January 26, 2011 18:39Check ora_sysevent coupled with ora_dict_obj_type in your trigger. This will help you capture the CREATE TABLE event.
Published by: Sissi Kandi on January 27, 2011 09:55
-
How to create a table with a column that is the value in another table?
Hi all,
It's my first post n I changed my ODI of DATASTAGE platform. Help me friends n I know basic steps in 11 ODI version which I was training in my company. I hope to have your support and can do everything an action ODI related documents.
My question is...
Table T1 > > > > > > > > > >
service id / / / attr.name / / / attr.value
S1 / / / product_code / / / P1
S1 / / / provider / / / pro1
S2 / / / product_code / / / P2
S3 / / / provider / / / pro3
Table T2 > > > > > > > > > > > > > > >
ID / / / product_code / / / provider
S1 / / / p1 / / / pro1
S2 / / / p2 / / / nullvalue
S3 / / / nullvalue / / / pro3
I have a table T1 since I should show the table T2 is released. Can we say everything on how to write a logic and steps to follow.
Thanks in advance.
Published by: 854662 on April 26, 2011 01:59Hello
U go.
1 the interface:
"Put a filter in your 1 on attr.name = array ' PRODUCT_CODE.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PRODUCT_CODE = TABLE1. ATTR_VALUEUse SQL IKM append control
Interface 2:
"Put a filter in your 1 on attr.name = array ' PROVIDER '.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PROVIDER = TABLE1. ATTR_VALUEDo SERVICE_ID as KEY (when you click the column target in properties, you can see KEY under properties of the target column) and use the incremental update of the IKM Oracle.
PS: I assume that Oracle as the source and target.
And you can refer to the documentation,
https://Apex.Oracle.com/pls/Apex/f?p=44785:24:4413167952886630:no:24:P24_CONTENT_ID, P24_PREV_PAGE:5185, 29
http://odiexperts.com/
And of course this OTN.
Thank you
Guru
Maybe you are looking for
-
Where to find the user's Guide English iBook to watch?
When you live is not in an English speaking country? I hate the user guides translated into your native language and still have my devices/Mac in English. The local store iBook does not contain an English version.
-
We use Firefox on your desktop windows 8.1 and a Net-book of Linux Mint, the problem is with the synchronization. Use of the Littlfox add-on on the net accountant to make the best use of space and a more decorative with the office. Those problem is w
-
function "clear recent history" - not available in the Tools tab is not clcikable - winXP?
WinXP - when I click on the menu Tools to clear recent history of the feature isn't available, I can see the name, but it is grayed out and is not clickable - the same for ctrl + shift del ... How can I solve this problem? How can I clear the cache?
-
Equium EA60-191: HARD disk faulty-need of replacement
I have a laptop Toshiba Equium EA60-191, which has a Fujitsu MHT2040AT hard drive installed. This drive is on its way, and I'm having some difficulty in finding the same type. Does anyone know a compatible player that will work in this phone? Thank y
-
where is the 4 channel scope?
I cannot display the scope of 4 ch, it is an add-on or I'm a delay?