ERROR at line 2: PL/SQL: Statement ignored - oracle

CREATE OR REPLACE TRIGGER log_FAMILY_increase
AFTER UPDATE OF FAMILY_INCOME ON STUDENT
FOR EACH ROW
BEGIN
INSERT INTO STUDENT_2 (NAME, SURNAME, NEW_FAMILY_INCOME)
VALUES (:NEW.NAME,SURNAME, :NEW.FAMILY_INCOME, 'New INCOME');
END;
in oracle 10g i get this error message:
ERROR at line 2: PL/SQL: Statement ignored

You're missing a column name here "(name, surname, new_family_income)", as you are trying to insert 4 values into 3 columns.. I switched the statement, to not list out the columns, maybe that will help..
CREATE OR REPLACE TRIGGER log_family_increase
AFTER UPDATE OF family_income
ON student
REFERENCING NEW AS new OLD AS old
FOR EACH ROW
BEGIN
INSERT INTO student_2
VALUES (:new.name,
:new.surname,
:new.family_income,
'New INCOME');
END;

Related

Getting error while creating Trigger in Oracle

I have created a trigger below but its giving me error as
3/1 PLS-00428: an INTO clause is expected in this SELECT statement 5/1 PL/SQL: SQL Statement ignored 6/28 PL/SQL: ORA-00984: column not allowed here Errors: check compiler log
Below is my code
create or replace TRIGGER "APP_WFM"."TRG_INS_NE_SF_SITE_INSTANCE"
BEFORE INSERT OR UPDATE ON NE_SITE_INSTANCE
FOR EACH ROW
BEGIN
select rf_siteid, sap_id, site_name from SF_NE_DETAILS;
INSERT INTO NE_SITE_INSTANCE (rf_siteid, sap_id, sitename)
VALUES (rf_siteid, sap_id, site_name);
END;
What can I try to resolve this?
Based on your previous question, you want to use the :NEW record to get the inserted values and then insert into the second table that you are copying into:
CREATE TRIGGER APP_WFM.TRG_INS_NE_SF_SITE_INSTANCE
BEFORE INSERT OR UPDATE ON NE_SITE_INSTANCE -- Table being copied from
FOR EACH ROW
BEGIN
INSERT INTO SF_NE_DETAILS ( -- Table being copied to
rf_siteid,
sap_id,
site_name
) VALUES (
:NEW.rf_siteid,
:NEW.sap_id,
:NEW.site_name
);
END;
/
db<>fiddle here

PL/SQL Invalid Identifier

While creating a trigger on the 'emprunter' table, I'm trying to compare a value coming from another table 'exemplaire.numexemplaire' which is supposed to be an INTEGER. But I keep getting the same errors which is:
Error(4,7): PL/SQL: SQL Statement ignored
Error(7,15): PL/SQL: ORA-00904: "EMPRUNTER"."NUMEXEMPLAIRE":
invalid identifier
How can I do to retrieve the value of a field coming from another table (exemplaire.numexemplaire)?
CREATE OR REPLACE TRIGGER BIEmprunter
BEFORE INSERT OR UPDATE OF numexemplaire ON emprunter
FOR EACH ROW
DECLARE
livreEmpruntable INTEGER;
BEGIN
SELECT exemplaire.empruntable
INTO livreEmpruntable
FROM exemplaire
WHERE emprunter.numexemplaire = exemplaire.numexemplaire;
IF livreEmpruntable != 1 THEN
raise_application_error(-20000, 'exemplaire non empruntable');
END if;
END;
UPDATE 1
Thanks for the answer but I keep getting this error whule trying to test the trigger...
SQL Error: ORA-04098: trigger 'EQUIPE10.ABONNEMENTPASAJOUR' is invalid and failed re-validation
04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"
*Cause: A trigger was attempted to be retrieved for execution and was
found to be invalid. This also means that compilation/authorization
failed for the trigger.
*Action: Options are to resolve the compilation/authorization errors,
disable the trigger, or drop the trigger.
Update 2
Thanks again for the answer, the trigger can compile now. But when now I'm trying to make it work when inserting value but I keep getting the error because there is no data yet...
INSERT INTO emprunter
VALUES (2, 1, 18, '17-02-01', null);
Error report -
SQL Error: ORA-01403: no data found
ORA-06512: at "EQUIPE10.BIEMPRUNTER", line 4
ORA-04088: error during execution of trigger 'EQUIPE10.BIEMPRUNTER'
01403. 00000 - "no data found"
*Cause: No data was found from the objects.
*Action: There was no data from the objects which may be due to end of fetch.
You want to join the two tables:
CREATE OR REPLACE TRIGGER BIEmprunter
BEFORE INSERT OR UPDATE OF numexemplaire ON emprunter
FOR EACH ROW
DECLARE
livreEmpruntable INTEGER;
BEGIN
SELECT exemplaire.empruntable
INTO livreEmpruntable
FROM exemplaire
join emprunter
ON emprunter.numexemplaire = exemplaire.numexemplaire;
IF livreEmpruntable != 1 THEN
raise_application_error(-20000, 'exemplaire non empruntable');
END if;
END;
Also, the above join query can potentially return multiple rows and the call will result in exception (uncaught as of now)
ORA-01422: exact fetch returns more than requested number of rows
I guess you want to use :new to access the record that triggered the trigger:
CREATE OR REPLACE TRIGGER BIEmprunter
BEFORE INSERT OR UPDATE OF numexemplaire ON emprunter
FOR EACH ROW
DECLARE
livreEmpruntable INTEGER;
BEGIN
SELECT exemplaire.empruntable
INTO livreEmpruntable
FROM exemplaire
WHERE :new.numexemplaire = exemplaire.numexemplaire;
IF livreEmpruntable != 1 THEN
raise_application_error(-20000, 'exemplaire non empruntable');
END if;
END;

Oracle PL-SQL: insert a rowtype after select - no enough values

Im trying to execute a block in PL/SQL that
Get the actual data of a row by doing table%rowtype
Modify an attribute from it
And then inserting the record in a INSERT INTO...VALUES statement like follows.
declare
v_record table%ROWTYPE
begin
select *
into v_record
from X_table;
insert into X_table values (v_record)
end;
But the error that raises when I do this is PL/SQL: ORA-00947: not enough values
I've solved this issue removing the parenthesis from the values selection in the INSERT statement.
For example:
insert into X_table values v_record;

PL SQL Stored Procedure for new Transaction and order

I'm giving a small snippet of my code but I 'm receiving the below error when trying to create a new order for a stored Oracle pl sql procedure.
line 83 is the insert statement in the code and line 84 is in the insert part of the statement.
83/5 PL/SQL: SQL Statement ignored
84/47 PL/SQL: ORA-00984: column not allowed here
BEGIN
--Initializing values for variables
x_rowcount := 0;
x_stockonhand := 0;
Totaldue := 0;
--Total due calculation
--(price of phone*quantity + shipping cost)*1.06 (assuming 6% sales tax)
Totaldue := (((i_price * c_p_qty) + i_shipping_cost) * 1.06);
SAVEPOINT start_transaction; -- mark a savepoint
--INSERT a new record into order table.
INSERT INTO orders(o_id,c_id,p_id,s_id,order_date,o_qty,order_total,card_type,cc_number,exp_date,shipping_status)
VALUES (orders_seq.nextval, c_c_id,c_p_id,s_id,sysdate,c_p_qty,Totaldue,c_card_type,c_cc_number,c_exp_date,'Not shipped yet');
Check your declaration section. Usually this error appears when you make a typo in variable name or variable not declared. For example:
SQL> create table tmp (id number, str varchar2(100));
Table created.
SQL> declare
a number;
begin
insert into tmp (id, str)
values (a, a1);
end;
/
values (a, a1);
*
ERROR at line 5:
ORA-06550: line 5, column 14:
PL/SQL: ORA-00984: column not allowed here
ORA-06550: line 4, column 3:
PL/SQL: SQL Statement ignored
The error is because one or more of the values in your VALUES(...,...) section is invalid.
I would suggest checking each one to see that they are valid. For example, is c_c_id declared and given a value somewhere else in the code? If not, this is likely your problem. Each one needs to be declared and given a value before it can be put in the VALUES(...,...) section of the INSERT statement.
INSERT INTO orders(o_id,c_id,p_id,s_id,order_date,o_qty,order_total,card_type,cc_number,exp_date,shipping_status)
VALUES (orders_seq.nextval, c_c_id,c_p_id,s_id,sysdate,c_p_qty,Totaldue,c_card_type,c_cc_number,c_exp_date,'Not shipped yet');

Error(3,31): PL/SQL: ORA-00984: Column is not allowed here

I am writing following oracle sql trigger
CREATE OR REPLACE TRIGGER scheme1.INSERTING_TRIGGER AFTER INSERT ON scheme1.Bill
FOR EACH ROW
BEGIN
INSERT INTO scheme2.DM_LOGGER(ID, TECHNOLOGY, WORKFLOW, NAME_EVENT, TIME_EVENT)
VALUES(scheme1.Bill.id,'Repository','UP','Accepted', SYSDATE);
END;
And it throws following errors:
Error(2,1): PL/SQL: SQL Statement ignored
Error(3,31): PL/SQL: ORA-00984: Column isn't allowed here.
If my guess is correct, the problem is in the ID column of the DM_LOGGER.
But I'm not sure what wrong it is about. I just want to insert the id from a new Bill record automatically in my logger.
You need to use the NEW record:
CREATE OR REPLACE TRIGGER scheme1.INSERTING_TRIGGER AFTER INSERT ON scheme1.Bill
FOR EACH ROW
BEGIN
INSERT INTO scheme2.DM_LOGGER(ID, TECHNOLOGY, WORKFLOW, NAME_EVENT, TIME_EVENT)
VALUES(:NEW.id,'Repository','UP','Accepted', SYSDATE);
END;
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/triggers.htm#LNPLS99955

Resources