I have this common problem with the trigger I created. I spent long time looking through any error but I could not find anything wrong though!
I am intending to create a trigger over my the table orders to be fired to warn the users when items in the ORDER reaches the re-order level.
CREATE OR REPLACE TRIGGER ORDERS_CHECK AFTER
INSERT OR UPDATE ON ORDERS
FOR EACH ROW
DECLARE
V_QTY ODETAILS.QTY%TYPE;
V_QOH PARTS.QOH%TYPE;
V_OLEVEL PARTS.OLEVEL%TYPE;
V_LEVEL_STATS EXCEPTION;
BEGIN
SELECT DOD.QTY, P.QOH, P.OLEVEL INTO V_QTY, V_QOH, V_OLEVEL
FROM PARTS P, ODETAILS OD
WHERE P.PNO = OD.PNO
AND OD.QTY = :NEW.QTY;
IF :OLD.QTY <= :NEW.V_OLEVEL THEN
RAISE V_LEVEL_STATS;
ELSE
DBMS_OUTPUT.PUT_LINE('Process has been completed successfully');
END IF;
EXCEPTION
WHEN V_LEVEL_STATS THEN
RAISE_APPLICATION_ERROR(-20002, 'Warning: Product with ID '|| :OLD.PNO ||'
contains only '|| :NEW.QTY ||' left over!');
END;
Compiler Error:
Error(13,17): PLS-00049: bad bind variable 'NEW.QTY'
Error(15,5): PLS-00049: bad bind variable 'OLD.QTY'
Error(15,17): PLS-00049: bad bind variable 'NEW.V_OLEVEL'
Error(23,64): PLS-00049: bad bind variable 'OLD.PNO'
Error(23,95): PLS-00049: bad bind variable 'NEW.QTY'
Related
i have created a trigger to my Oracle task and got some errors and i'm trying to solve but don't know how. I was searching fix to my error but i didn't find helpful solution
Is someone can help me to do it, please?
So here's my code:
create table sourcetablename_log (
id number,
operation_date date,
old_username varchar2(20),
new_username varchar2(20),
old_first_name varchar2(20),
new_first_name varchar2(20),
old_last_name varchar2(20),
new_last_name varchar2(20),
action varchar2(20),
author varchar2(20)
);
create or replace trigger src_log
before insert or delete or update on sourcetablename_log
for each row
begin
if inserting then
insert into sourcetablename_log(id, operation_date, new_username, new_firstname, new_lastname)
values (:new.id, sysdate, :new.username, :new.firstname, :new.lastname);
elsif updating then
insert into sourcetablename_log(id, operation_date, old_username, new_username, old_firstname, new_firstname, old_lastname, new_lastname)
values (:new.id, sysdate, :old.username, :new.username, :old.firstname, :new.firstname, :old.lastname, :new.lastname);
elsif deleting then
insert into sourcetablename_log(id, operation_date, old_username, new_username, old_firstname, new_firstname, old_lastname, new_lastname)
values (:new.id, sysdate, :old.username, :new.username, :old.firstname, :new.firstname, :old.lastname, :new.lastname);
end if;
end src_log;
And here's an error:
LINE/COL ERROR
--------- -------------------------------------------------------------
4/27 PLS-00049: bad bind variable 'NEW.USERNAME'
4/42 PLS-00049: bad bind variable 'NEW.FIRSTNAME'
4/58 PLS-00049: bad bind variable 'NEW.LASTNAME'
7/27 PLS-00049: bad bind variable 'OLD.USERNAME'
7/42 PLS-00049: bad bind variable 'NEW.USERNAME'
7/57 PLS-00049: bad bind variable 'OLD.FIRSTNAME'
7/73 PLS-00049: bad bind variable 'NEW.FIRSTNAME'
7/89 PLS-00049: bad bind variable 'OLD.LASTNAME'
7/104 PLS-00049: bad bind variable 'NEW.LASTNAME'
10/27 PLS-00049: bad bind variable 'OLD.USERNAME'
10/42 PLS-00049: bad bind variable 'NEW.USERNAME'
10/57 PLS-00049: bad bind variable 'OLD.FIRSTNAME'
10/73 PLS-00049: bad bind variable 'NEW.FIRSTNAME'
10/89 PLS-00049: bad bind variable 'OLD.LASTNAME'
10/104 PLS-00049: bad bind variable 'NEW.LASTNAME'
Errors: check compiler log
My problem is:
Automate creation of logging table and associated with it triggers A Create a stored procedure that creates a LOGGING table with corresponding columns of OLD values and NEW values, ACTION column, that should be filled in by type of an ACTION and user name (AUTHOR)
Example: You have a table USER of users with next columns:
USERNAME VARCHAR
FIRST_NAME VARCHAR
LAST_NAME VARCHAR
Your procedure should produce a new table with name of “SOURCETABLENAME”_LOG - in this case - USER_LOG with next columns:
ID NUMBER [or OPERATION_ID NUMBER]
OPERATION_DATE DATE
OLD_USERNAME VARCHAR
NEW_USERNAME VARCHAR
OLD_FIRST_NAME VARCHAR
NEW_FIRST_NAME VARCHAR
OLD_LAST_NAME VARCHAR
NEW_LAST_NAME VARCHAR
ACTION VARCHAR
AUTHOR VARCHAR**
If column name is e.g. new_username, then you'd use :new.new_username, not just :new.username.
The same goes for all other columns.
For example:
insert into sourcetablename_log(id, operation_date, new_username, new_firstname, new_lastname)
values (:new.id, sysdate, :new.new_username, :new.new_firstname, :new.new_lastname);
Hi I want to create a trigger which will insert values on relational table A_EQ, A_U and A_P after inserting the values to entity table ACCOUNTS. The values will the inserted into A_EQ if only the ACCOUNTS.TYPE='Equipments', into A_U if only ACCOUNTS.TYPE='Utility' and into A_P for the rest.
Whenever I'm trying to compile the trigger certain errors are showing:
Error(40,13): PLS-00049: bad bind variable 'NEW.A_U'
Error(41,13): PLS-00049: bad bind variable 'NEW.A_U'
Error(42,13): PLS-00049: bad bind variable 'NEW.A_U'
Error(45,9): PLS-00049: bad bind variable 'NEW.A_EQ'
Error(46,13): PLS-00049: bad bind variable 'NEW.A_EQ'
Error(47,13): PLS-00049: bad bind variable 'NEW.A_EQ'
Error(50,9): PLS-00049: bad bind variable 'NEW.A_P'
Error(51,13): PLS-00049: bad bind variable 'NEW.A_P'
Error(52,13): PLS-00049: bad bind variable 'NEW.A_P'
Error(57,4): PLS-00103: Encountered the symbol ";" when expecting one of the following: if
The Code for trigger is given below:
create or replace trigger accounts_relational_insert
after insert on accounts
REFERENCING NEW AS new OLD AS Old
for each row
declare
sys_month VARCHAR2 (10) ;
i_month VARCHAR2 (10);
old1 int;
curr_amount number (20,2);
curr_id varchar2 (20);
curr_txn varchar2 (20);
curr_type varchar2 (20);
begin
select to_char(SYSDATE,'Month') into sys_month from dual;
select ACCOUNTS_ID_SEQ.currval into old1 from dual;
select to_char(paid_on,'Month') into i_month from accounts where transaction_id ='Txn' || lpad(old1,9,'0');
select amount into curr_amount from accounts where transaction_id='Txn' || lpad(old1,9,'0');
select id into curr_id from accounts where transaction_id='Txn' || lpad(old1,9,'0');
select transaction_id into curr_txn from accounts where transaction_id='Txn' || lpad(old1,9,'0');
select type into curr_type from accounts where transaction_id='Txn' || lpad(old1,9,'0');
if i_month = sys_month then
if curr_type ='Utility' then
:new.a_u.transaction_id := curr_txn;
:new.a_u.u_id :=curr_id;
:new.a_u.amount := curr_amount;
else if curr_type='Equipments' then
:new.a_eq.transaction_id := curr_txn;
:new.a_eq.eq_id :=curr_id;
:new.a_eq.amount := curr_amount;
else
:new.a_p.transaction_id := curr_txn;
:new.a_p.barcode:=curr_id;
:new.a_p.amount := curr_amount;
end if;
end if;
end;
The Tables are given below:
It will be very helpful if someone tells me how to resolve this error and also if there is any other way to insert into relational tables after inserting on accounts table.
You can rearrange the trigger simply as simple as this one
CREATE OR REPLACE TRIGGER accounts_relational_insert
AFTER INSERT ON accounts
FOR EACH ROW
BEGIN
IF TO_CHAR(:new.paid_on, 'YYYYMM') = TO_CHAR(sysdate, 'YYYYMM') THEN
IF :new.type = 'Utility' THEN
INSERT INTO a_u VALUES(:new.id, :new.transaction_id, :new.amount);
ELSIF :new.type = 'Equipments' THEN
INSERT INTO a_eq VALUES(:new.id, :new.transaction_id, :new.amount);
ELSE
INSERT INTO a_p VALUES(:new.id, :new.transaction_id, :new.amount);
END IF;
END IF;
END;
/
where
the values, which are already been able to get from identifiers of
columns of the table accounts qualified with :new , to be
inserted shouldn't return from SELECT statements. Moreover, you would get mutating
trigger error for this case.
indeed, defining the local variables are not needed due to the fact
that expressed above, and also values for i_month and sys_month
will directly be derived from TO_CHAR(:new.paid_on, 'YYYYMM') and
TO_CHAR(sysdate, 'YYYYMM') respectively. Btw, do not prefer using string
expression within character conversion such as Month, since you might not
only face case sensitivity issues, but also might fail for international
studies related to language differences.
the trigger is created on accounts table, for the other tables you
should use INSERT statements, cannot use such variable assignments.
The expression REFERENCING NEW AS new OLD AS old is redundant, as
being default.
I have below item table in which I have applied trigger.
Name Null? Type
---------- ----- -------------
ID NUMBER(10)
ENTITYNAME VARCHAR2(100)
SYNONYMS VARCHAR2(100)
I am inserting data into dynamicentity table. structure is below.
Name Null? Type
---------- ----- ------------
ID NUMBER(38)
ENTITYNAME VARCHAR2(45)
SYNONYMS VARCHAR2(45)
OPERATION VARCHAR2(10)
TABLENAME VARCHAR2(45)
Whenever I am doing dml in item table value is getting inserted into dynamicentity table.
Below is the trigger. It is compiling in one env but not in another env.
set define off;
Create or replace trigger item_trigger
before insert or update or delete on item
for each row
begin
If inserting then
Insert into dynamicentity values(:new.id,:new.entityname,:new.synonyms,'add','ItemEntity');
end if;
if deleting then
Insert into dynamicentity values(:old.id,:old.entityname,:old.synonyms,'delete','ItemEntity');
end if;
if updating then
Insert into dynamicentity values(:new.id,:new.entityname,:new.synonyms,'modify','ItemEntity');
end if;
End item_trigger;
I am getting below error while compiling trigger
Trigger ITEM_TRIGGER compiled
LINE/COL ERROR
--------- -------------------------------------------------------------
3/34 PLS-00049: bad bind variable 'NEW.ID'
3/42 PLS-00049: bad bind variable 'NEW.ENTITYNAME'
6/34 PLS-00049: bad bind variable 'OLD.ID'
6/42 PLS-00049: bad bind variable 'OLD.ENTITYNAME'
9/34 PLS-00049: bad bind variable 'NEW.ID'
9/42 PLS-00049: bad bind variable 'NEW.ENTITYNAME'
Errors: check compiler log
I'm getting this error i try to fix it without success, i have controlled the table that i use to to this trigger but it doesn't work.
this is the code,
create or replace TRIGGER INSERISCITURNO
instead of insert on VistaTurno for each row
declare
ok boolean;
begin
ok := false;
for i in (select a.Giocatore from AVATAR a where a.Partita = :new.Partita ) loop
if (:new.Giocatore = i.Giocatore) then
insert into TURNO(CodTurno, NumTurno, Partita, Giocatore) values (:new.CodTurno, :new.NumTurno, :new.Partita, :new.Giocatore);
AggiornaSituazioneGiocatore(:new.Giocatore, :new.CodTurno, :new.Partita);
ok := true;
end if;
end loop;
if(ok = false) then
dbms_output.put_line('Il giocatore è in partita, inserimento fallito!');
end if;
end;
they give me this error on compilation,
Errore(8,68): PLS-00049: bad bind variable 'NEW.PARTITA'
Errore(9,11): PLS-00049: bad bind variable 'NEW.GIOCATORE'
Errore(10,75): PLS-00049: bad bind variable 'NEW.CODTURNO'
Errore(10,90): PLS-00049: bad bind variable 'NEW.NUMTURNO'
Errore(10,105): PLS-00049: bad bind variable 'NEW.PARTITA'
Errore(10,119): PLS-00049: bad bind variable 'NEW.GIOCATORE'
Errore(11,39): PLS-00049: bad bind variable 'NEW.GIOCATORE'
Errore(11,55): PLS-00049: bad bind variable 'NEW.CODTURNO'
Errore(11,70): PLS-00049: bad bind variable 'NEW.PARTITA'
pls, can someone help me? i think the syntax is good.
add VistaTurno
CREATE OR REPLACE FORCE VIEW VISTATURNO (
"CODTURNO", "NUMTURNO", "PARTITA", "GIOCATORE"
) AS
select * from TURNO;
and this is the Turno
create table TURNO (
CodTurno integer primary key ,
NumTurno integer not null ,
Partita integer,
Giocatore integer
);
alter table TURNO
add constraint v4 check (NumTurno > 0);
alter table TURNO
add constraint fk1 FOREIGN KEY (Partita) REFERENCES PARTITA(CodPartita);
alter table TURNO
add constraint fk2 FOREIGN KEY (Giocatore) REFERENCES
GIOCATORE(CodGiocatore);
enter image description here
I checked all my fields and everything is fine but i keep on getting this error
When i write this trigger on sql command it says trigger has been created but when i checked on the trigger it showed invalid
This is my trigger
create or replace trigger "Max_Crew_T1"
Before insert or update on "CREW"
for each row
declare
v_count number;
Begin
select count(*) into v_count from CREW where AirPlaneID=:NEW.AirPlaneID;
if
v_count > 5
then
Raise_Application_ERROR(-20343,'Crew number exceeded');
END IF;
END;
HERE IS THE ERROR MESSAGE;
PLS-00049: bad bind variable 'NEW.AIRPLANEID'
click on the link below for table desc
The error is because you defined the airplane id while creating the table in quotes. I.e "AirPlaneID" hence you need to do the same in the trigger.
It is not a good practice to define case-sensitive columns with quotes as it causes all these issues, its much better to define without quotes eg. create table crew (airplaneid number(6))..etc. Anyway..
Please use below:
create or replace trigger "Max_Crew_T1"
Before insert or update on "CREW"
for each row
declare
v_count number;
Begin
select count(*) into v_count from CREW where "AirPlaneID"=:NEW."AirPlaneID";
if
v_count > 5
then
Raise_Application_ERROR(-20343,'Crew number exceeded');
END IF;
END;