invalid trigger specification in oracle [closed] - oracle

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
DROP TABLE a CASCADE CONSTRAINTS;
CREATE TABLE a(
cyear VARCHAR2(4));
CREATE TRIGGER current_year
BEFORE INSERT ON cyear
FOR EACH ROW SET NEW.year = year(NOW());
EDIT:
I tried this,
CREATE TRIGGER current_year
BEFORE INSERT ON a
FOR EACH ROW
BEGIN
:NEW.cyear = TO_CHAR(SYSDATE, 'YYYY');
END current_year;
I keep getting the PLS-00103 error.

Trigger created on tables, not on columns
In Oracle variables are not assigned with SET
There is no build-in function called NOW in Oracle
NEW and OLD are accessible only in WHEN clause; in other places they should be preceded by colon (:NEW, :OLD)
END keyword is missed at the end (and BEGIN in the beginning of the trigger body)

Related

Oracle sql developer trigger error ORA-04088: error during execution of trigger 'SYSTEM.LRES_PROTOKOLL' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I create a trigger
create or replace TRIGGER trj2
BEFORE INSERT OR UPDATE OF
customer_ID ON Reserve
FOR EACH ROW
DECLARE
new_fk1_NR VARCHAR2(7);
BEGIN
SELECT NR
INTO new_fk1_NR
FROM customers
WHERE :NEW.customer_ID= customers.ID;
:NEW.NR_K := new_fk1_NR;
END;
It is working fine for update statements, but for insert it give this error
ORA-01403: no data found ORA-06512: at "SYSTEM.WRITERESPROT", line 76
ORA-06512: at "SYSTEM.LRES_PROTOKOLL", line 38
ORA-04088: error during execution of trigger 'SYSTEM.LRES_PROTOKOLL'
I couldn't find links or explanations about what does this mean,
any help please?
The problem is when no rows are returned. A simple way to ensure that exactly one row is returned is to use aggregation:
SELECT MAX(NR)
INTO new_fk1_NR
FROM customers
WHERE :NEW.customer_ID = customers.ID;
An aggregation query with no GROUP BY returns exactly one row, even when no rows match. If no rows match, the result is NULL.
This error is raised becaue your SELECT ... INTO ... query returned no record. You would need to either ensure that the query always returns one record, or to handle that exception.
Something like this will handle exceptions:
create or replace trigger trj2
before insert or update of customer_id on reserve
for each row
declare
new_fk1_nr varchar2(7);
begin
select nr into new_fk1_nr from customers where :new.customer_id= customers.id;
:new.nr_k := new_fk1_nr;
exception
when NO_DATA_FOUND
then raise_application_error(
-20010,
'this could not happen since customer does not exist'
);
when others
then raise_application_error(-20011,'Unknown Exception');
end;
/

Oracle Trigger: Encountered the symbol ";" when expecting one of the following: if [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
This is the code that produces that error:
create or replace trigger "T4"
AFTER
update of "VALORE" on "OFFERTA"
for each row
DECLARE
cs Inserzione.PrezzoF%TYPE;
BEGIN
SELECT I.PrezzoF INTO cs
FROM Inserzione I JOIN Offerta O ON I.Codice = O.Codice
WHERE O.Codice = :old.Codice;
IF (cs!=NULL AND new.Valore >= cs) THEN
UPDATE Inserzione
SET Stato = 'OFF';
ENDIF;
END;​
I don't understand why, because it seems correct.
The error is: 13 4 PLS-00103: Encountered the symbol ";" when expecting one of the following: if
There are a few syntax errors.
The one that is throwing the error is, as #Multisync points out in the comments, that ENDIF should be END IF.
Beyond that, though, there are a couple of other issues.
new.Valore should be :new.Valore-- the :new and :old pseudorecords need to be prefixed with a colon.
cs!=NULL will always return FALSE even if cs is actually NULL (technically, it will always return "unknown" which will be interpreted as false). You would need to use cs IS NOT NULL if you want to check to see if cs is NULL.
I'll strongly wager that your UPDATE statement is missing a WHERE clause-- I don't believe that you really want to update every row of the Inserzione table. Most likely, you'd need to add WHERE codice = :old.codice.
Updated UPDATE
UPDATE Inserzione i
SET Stato = 'OFF'
WHERE i.codice = :old.codice;
You cannot generally SELECT from the table that the trigger is defined on in a row-level trigger. That will generally raise a mutating table exception. I suspect that the join to offerta in your SELECT statement isn't needed. You probably just want something like
Updated SELECT
SELECT i.prezzoF
INTO cs
FROM inserzione i
WHERE i.codie = :old.codice;

Why do I get ORA:0922 error:missing or invalid option [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Whats wrong with the following procedure?? I have checked the code for syntax errors but I m unable to find one.
CREATE OR REPLACE Edit_premium_amt
(
policy_number IN number(4),
new_premium_type IN varchar2(4)
)
IS
discount_amount number(6,2);
premium_amts number(11,2);
policy_amts number(11);
dur number(5);
prem_type varchar2(4);
disc_weigh varchar2(2);
disc_perc number(2);
prem_type_int number(2,1);
BEGIN
prem_type:=new_premium_type;
UPDATE policy SET premium_type=new_premium_type WHERE policy_id=policy_number;
SELECT policy_amt,duration INTO policy_amts,dur WHERE policy_id=policy_number;
SELECT disc_weightage INTO disc_weigh FROM disc_details WHERE duration=dur;
SELECT percent INTO disc_perc FROM disc_calculation WHERE premium_type=prem_type AND
weightage=disc_weigh;
CASE prem_type
WHEN 'HY' THEN prem_type_int:=2.0;
WHEN 'Y' THEN prem_type_int:=1.0;
ELSE prem_type_int:=0.5;
END CASE;
discount_amount:= ((policy_amts)/dur)/prem_type_int))*disc_perc;
premium_amts:=policy_amts-discount_amount;
UPDATE policy SET premium_amt=premium_amts
WHERE policy_id=policy_number;
END Edit_premium_amt;
You must say what you are creating or replacing
In this case CREATE OR REPLACE PROCEDURE Edit_premium_amt............

Unable to insert date to table [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to insert a date into oracle table using below
SQL> insert into temp (tst,thistime) values ('test3',TO_DATE('MM/DD/YYYY HH24:MI
:SS','01/01/2014 16:45:45') );
but its giving below error
ERROR at line 1:
ORA-01821: date format not recognized
Below is the description of table
SQL> describe temp;
Name Null? Type
----------------------------------------- -------- ---------------------------
TST VARCHAR2(10)
THISTIME DATE
Use the insert . . . select form of insert:
insert into temp (tst, thistime)
select 'test3', TO_DATE('01/01/2014 16:45:45', 'MM/DD/YYYY HH24:MI:SS')
from dual;
In addition to having the arguments backwards for to_date(), values doesn't evaluate expressions that belong in a select statement.

Trying to create a table, but it comes up with this error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am new to mysql and I can't really figure out as to why I keep on getting the missing right parenthesis error from this code:
/*second oracle program */
/*Franklin Tong */
set echo on
spool c:hw3.text
drop table student;
create table student(
snn char(9),
lastname char(10),
firstname char(10),
major char(10),
GPA number(3,2)
DOB date
);
insert into student (111,Smith,Johnny,IS,3.41,5/18/82);
insert into student (102,Smith,Jack,FIN,3.25,3/11/80);
select * from student;
spool off
system returns a message saying:
error at line 7
ora-00907: missing right parathesis
You are missing a ',' after 'GPA number(3,2)'.
You should put a comma ',' after 'GPA number(3,2)'.

Resources