Oracle Warning: execution completed with warning - sql

I have two tables
Orders(ID,ORDERDATE,DELIVERYDATE,GOODID,QUANTITY,COLLECTIONFROM,DELIVERYTO,NOTES)
and
ROLLINGSTOCK_ORDER(ORDERID,ROLLINGSTOCKID,DEPARTUREDATE,DELIVERYDATE,ROUTEID)
i have created a trigger to update the DELIVERYDATE in ROLLINGSTOCK_ORDER when DELIVERYDATE is updated in Orders
CREATE OR REPLACE TRIGGER TRIGGER_UpdateDeliveryDate
BEFORE UPDATE OF DELIVERYDATE ON Orders
FOR EACH ROW
BEGIN
then
UPDATE LOCOMOTIVE_DRIVER ld
set ld.DELIVERYDATE = :new.DELIVERYDATE
where ld.orderid = :new.id
end if;
END;
When i run it i get the following message
Warning: execution completed with
warning TRIGGER
TRIGGER_UpdateDeliveryDate Compiled.
The warning does not give me any information so
How can i see the details of the warning?
The trigger seems ok to me can you spot the problem?
Thanks

Earlier this week you asked a question on writing a trigger to execute a conditional update. I posted two examples of how to achieve that end. What you appear to have done is mash the two examples into a single spavined trigger which doesn't compile.
To be clear you need just one of the following. Either
BEFORE UPDATE OF DELIVERYDATE ON Orders
or
BEFORE UPDATE ON Orders
...
if :new.delivery_date != :old.delivery_date then
Use the first option if you just have the one piece of logic to apply. Use the second version if you want your trigger to handle other pieces of logic as well, which is usually the case.

You write
BEGIN
then
which is incorrect syntax. Are you missing an IF?
You are also missing a semicolon (;) after your UPDATE.
You might get the error using
Show Error Trigger TRIGGER_UpdateDeliveryDate

Related

need help writing this compound trigger

i have a column in my table that i need to update on insert or update, i can't do it with a simple trigger because the new value has to be SELECTED from the same table and other tables (which would generate trigger is mutating error).
my solution was to use a compound trigger, after a little bit of documentation i wrote this code:
CREATE OR REPLACE TRIGGER update_contract_n FOR
INSERT OR UPDATE ON contract
COMPOUND TRIGGER
v_n VARCHAR(70);
AFTER EACH ROW IS BEGIN
v_n := object_contract(:new.id_contract);
END AFTER EACH ROW;
AFTER STATEMENT IS BEGIN
UPDATE contract
SET
n = v_n
WHERE
id_contract = :new.id_contract;
END AFTER STATEMENT;
END update_contract_n;
the function object_contract() joins 4 tables one of which is the table contract and returns a varchar.
when i compile the trigger code i get this error :
pls-00679 trigger binds not allowed in before/after statement section
but i don't know what i'm doing wrong since the variable binding was done in AFTER EACH ROW section not in AFTER STATEMENT.
any help would be appreciated (fixing or rewriting the code), a simple guide on how to use a compound trigger would also be appreciated.
EDIT:
i found the problem, i was referencing :new.id_contract in AFTER STATEMENT and i fixed it, but now i am getting table is mutating trigger/function may not see it
how can i fix that?

A Trigger which will implement update cascade to PK

I need to write a trigger which will implement update cascade for (gameno) code for SummerGames but I keep encountering `Error(11,1): PLS-00103: Encountered the symbol "CREATE
I'm using Oracle SQL Developer.
My current code:
create or replace TRIGGER SG_GAMENO_UPDATE
BEFORE UPDATE OF SG_GAMENO ON SUMMERGAMES
FOR EACH ROW
BEGIN
UPDATE SUMMERGAMES
SET SG_GAMENO = :new.SG_GAMENO
WHERE SG_GAMENO = :old.SG_GAMENO;
END;
You need to end the trigger statement, which is partly PL/SQL, with a / on a line on its own. That will end the statement and cause it to be run.
create or replace TRIGGER SG_GAMENO_UPDATE
BEFORE UPDATE OF SG_GAMENO ON SUMMERGAMES
FOR EACH ROW
BEGIN
UPDATE SUMMERGAMES
SET SG_GAMENO = :new.SG_GAMENO
WHERE SG_GAMENO = :old.SG_GAMENO;
END;
/
At the moment whatever is folowing this in your script - which seems to be another create statement - is being seen as part of the same trigger creation, and that keyword isn't valid within a block.
Your trigger doesn't seem to make any sense, and at best will lead to infinite recursion when you attempt an update (which will be detected and killed), but that's a separate issue. Perhaps you meant to update a child table, rather than the same table the trigger is against. But you shouldn't really be updating a PK at all; that's why synthetic keys are generally preferred over natural ones. gameno sounds synthetic anyway.
it will something about the separation of your codes, i mean when you executed the code snippet above, you marked off some part from another code, that's why you get syntactic error. try to execute just the code above, delete anyting else from the sql editor

Informix SQL update command error 746

I tried to update the field "contract_id" in the table "contract_scan_image".
However, the update was failed and an error "746: Field contract_id and type of contract_scan_image cannot be updated!" was shown.
My SQL command is:
update contract_scan_image
set contract_id = '14864730'
where contract_id = '1486473'
and type = 'RM'
and account = '00193400944'
Does anyone know what happened and how to fix it?
Error message -746 is for user-defined errors. It typically is used in stored procedures in a RAISE EXCEPTION statement:
RAISE EXCEPTION -746, 0, "Field contract_id and type of contract_scan_image cannot be updated!"
The actual message text for error -746 in the message files is:
%s
That is, it prints the string it is given as a string.
So, you are going to need to track down the triggers and stored procedures invoked by those triggers on the contract_scan_image table, and deduce from where the error is generated what you are doing wrong. Superficially, though, it appears that you are not allowed to alter the contract ID, yet that is what you are trying to do.
First things first, I would take a look at a list of Reserved words in SQL - https://drupal.org/node/141051
I would get in the habit of surrounding fields with `` See below:
update contract_scan_image
set `contract_id` = '14864730'
where `contract_id` = '1486473'
and `type` = 'RM'
and `account` = '00193400944'
** Note - type is a reserved word
The error is caused by something being triggered. Then no table can be modified by UPDATE command.
Finally I deleted the record I want to update. Then added back the modified record.
I copy the error description here from the net for reference.
BTW, I asked my supervisor and he said he did trigger something to cause this. (He didn't tell me how to un-trigger it...)
-746
THE SQL STATEMENT IN FUNCTION, TRIGGER, OR IN STORED PROCEDURE name VIOLATES THE NESTING SQL RESTRICTION
Explanation
If a table is being modified (by INSERT, DELETE, UPDATE, or MERGE), the table can not be accessed by the lower level nesting SQL statement.
If any table is being accessed by a SELECT statement, no table can be modified (by INSERT, DELETE, UPDATE, or MERGE) in any lower level nesting SQL statement.
System action
The SELECT, INSERT, DELETE, UPDATE or MERGE SQL statement failed.
Programmer response
Remove the failing statement from the named function, trigger or the stored procedure.
SQLSTATE
57053

Strange error when using output clause on an update statement?

Firstly, a lot of people are unfamiliar with output in my experience. If so, this link is very handy: Hidden Features of SQL Server
I have the following update statement:
UPDATE lease_deal.lease_budget
SET change_type = NULL
OUTPUT inserted.*
WHERE ISNULL(change_type, '') = ''
Although I thought this would return the updated records for me I'm receiving the following error:
Msg 334, Level 16, State 1, Line 9 The target table
'lease_deal.lease_budget' of the DML statement cannot have any enabled
triggers if the statement contains an OUTPUT clause without INTO
clause.
I know I can successfully create a temporary table and redirect the updated records there using the output statement, but why can't I return it to the IDE? I'm sure (certain) I've been able to do this before but can't seem to find a suitable example anywhere to help me understand what I'm doing wrong. Is this simply not possible when you have triggers on a column that you're updating?
This
http://msdn.microsoft.com/en-au/library/ms177564.aspx
says this
If the OUTPUT clause is specified without also specifying the INTO keyword, the target of the DML operation cannot have any enabled trigger defined on it for the given DML action. For example, if the OUTPUT clause is defined in an UPDATE statement, the target table cannot have any enabled UPDATE triggers.

Oracle - Trigger is created, but gives error anytime data is updated

I'm creating the following trigger:
CREATE TRIGGER Trigger_UpdateTrainingDelivery
AFTER DELETE OR INSERT OR UPDATE OF STARTDATE
ON TPM_TRAININGPLAN
BEGIN
UPDATE TPM_PROJECTVERSION V
SET TRAININGDELIVERYSTART = (SELECT MIN(STARTDATE) FROM TPM_TRAININGPLAN WHERE PROJECTID=V.PROJECTID AND VERSIONID=V.VERSIONID AND TRAININGPLANTYPE='prescribed')
END;
When I create it, I get a warning:
Warnings: --->
W (1): Warning: execution completed with warning
<---
However, it's still created it anyway. When I then modify a row in TPM_TRAININGPLAN, I get an error:
>[Error] Script lines: 12-12 ------------------------
ORA-04098: trigger 'TPMDBO.TRIGGER_UPDATETRAININGDELIVERY' is invalid and failed re-validation
Script line 12, statement line 1, column 7
Is there something wrong with my trigger? I can run the UPDATE statement in the trigger by itself and it runs fine, so I don't think there's anything wrong with that.
It appears that you are missing a semicolon at the end of your UPDATE statement.
If you query USER_ERRORS, you'll get the same error information that SQL*Plus will give you with the SHOW ERRORS command without needing to have access to SQL*Plus.
SELECT line, position, text
FROM user_errors
WHERE name = 'TRIGGER_UPDATETRAININGDELIVERY'
ORDER BY sequence
What was the error being reported during compilation?
SQL> show errors trigger trigger_updatetrainingdelivery
Ok I figured this out. It's actually a bug in Aqua Data Studio, which I'm using to run the query. For some reason, it doesn't handle semi-colons within the triggers correctly. I will report this bug, but I did find a workaround:
File->Options->General
Uncheck: ';' Statement separator