Subprogram or cursor 'USER' reference is out of scope - sql

I'm trying to define a trigger which fires before any insert in Cliente table but I'm absolutely unable to do so. Here it is:
CREATE OR REPLACE TRIGGER updateSaldoCuenta
BEFORE INSERT ON Cliente
FOR EACH ROW
BEGIN
RAISE_APPLICATION_ERROR(-20000, 'TRY');
END;
/
And here's the error I'm getting:
BEFORE INSERT ON Cliente
*
ERROR at line 2:
ORA-06552: PL/SQL: Compilation unit analysis terminated
ORA-06553: PLS-225: subprogram or cursor 'USER' reference is out of scope
Any help is appreciated!

Just creating a new user did the trick! I suppose something went wrong with the other

Related

Oracle PL/SQL - BEFORE INSERT 'table does not exist' error?

I'm taking my first steps in Pl/SQL and am struggling with triggers. I've tried creating the trigger below but am receiving this error:
Error at line 2: PL/SQL: SQL Statement ignored
PL/SQL: ORA-00942: table or view does not exist
To clarify: I have checked the name of the table over and over, and it does exist. It is also in the same schema as the trigger I'm trying to create. The 'customer_seq.NEXTVAL' refers to a sequence created previously that runs without errors.
The code is as follows:
CREATE TRIGGER new_customer
BEFORE INSERT ON customer
FOR EACH ROW
BEGIN
INSERT INTO customer_id VALUES ('c-', customer_seq.NEXTVAL);
END;
Thanks in advance for any help.
You probably intend something like this:
CREATE TRIGGER new_customer
BEFORE INSERT ON customer
FOR EACH ROW
BEGIN
SELECT customer_seq.NEXTVAL INTO :NEW.customer_id
FROM dual;
END;
It is unclear what the purpose of 'C_' is. If it is part of the customer id, I would advise you to stick to numbers.
Also note that more recent versions of Oracle support generated always as identity -- which is much preferred over defining a sequence and trigger.

How to make a trigger in ORACLE PL/SQL to not allow double values?

I've a table named cliente with columns: COD_CLIENTE, CPF_CLIENTE and NAME_CLIENT.
How to make a TRIGGER in PL SQL to not allow insert or update double CPF_CLIENTE's values?
I've tryied:
CREATE OR REPLACE TRIGGER TG_CPF
BEFORE INSERT ON CLIENTE
FOR EACH ROW
DECLARE
CONDITION_CHECK NUMBER;
BEGIN
SELECT COUNT(CPF_CLIENTE) INTO CONDITION_CHECK FROM CLIENTE WHERE CPF_CLIENTE = :new.CPF_CLIENTE;
IF CONDITION_CHECK > 0 THEN
RAISE_APPLICATION_ERROR (-20000, ' CPF is Already in DB.');
END IF;
END;
/
But i got:
ORA-20000: CPF is Already in DB.
ORA-06512: at "USER.TG_CPF", line 6
ORA-04088: error during execution of trigger 'USER.TG_CPF'
Why I'm getting ORA-06512 and ORA-0488 errors?
The trigger does what i need. Don't insert/update the value if already exits, but i'm getting these 2 errors.
How to fix it, please?
Thank you!
You cannot have a trigger on a table, and read data from that same table in the trigger body, when it's a row level trigger.
Instead, you need to use a unique constraint.

Error: ORA-00969: missing ON keyword - Oracle

I am using Oracle 11g XE database and Oracle SQL developer to execute SQL statements.
I have this SQL statement which is giving me the above compiler error when executing it.
CREATE OR REPLACE
TRIGGER "STD"."TRG_STUDENT"
BEFORE INSERT,DELETE
ON STUDENT
FOR EACH ROW
BEGIN
IF INSERTING THEN
DBMS_OUTPUT.PUT_LINE('Inserting !!');
END IF;
IF DELETING THEN
DBMS_OUTPUT.PUT_LINE('Deleting !!');
END IF;
END;
I tried some variations but I used to get other errors.
I placed the ON STUDENT just before the BEFORE INSERT,DELETE line and I get this error:
Error: ORA-04071: missing BEFORE, AFTER or INSTEAD OF keyword
What am I missing here?
BEFORE INSERT OR DELETE
More about Create Trigger syntax: http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7004.htm
Use BEFORE INSERT OR DELETE instead of BEFORE INSERT, DELETE. Refer coding trigger for more in detail.

Oracle Trigger create with compilation errors

I wrote the below trigger to prevent users from allocating a Class to a Session if the Class Date does not match the day of the week the Session is on.
CREATE OR REPLACE TRIGGER trig_alternative_classDate
AFTER INSERT OR UPDATE ON ALTERNATIVE
FOR EACH ROW
DECLARE
classdate CHAR;
sessionday VARCHAR;
BEGIN
SELECT to_char(to_date(class.class_date), 'Day') INTO classdate, sessions.day INTO sessionday
FROM SESSIONS, CLASS, DUAL, LOCATION, ALTERNATIVE
WHERE class.class_id = alternative.class_id
AND alternative.location_id = location.location_id
AND sessions.location_id = location.location_id;
IF sessions.day != to_char(to_date(class.class_date), 'Day')
THEN raise_application_error(-20999,'Invalid Class Date - Class Date does not match Session Day');
END IF;
END;
/
However I get an error message when I run the trigger
Warning: Trigger created with compilation errors.
SQL> show error trigger trig_alternative_classDate
Errors for TRIGGER TRIG_ALTERNATIVE_CLASSDATE:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/2 PL/SQL: SQL Statement ignored
5/80 PL/SQL: ORA-00923: FROM keyword not found where expected
Could someone please help?
Remove second INTO - only one INTO is needed:
INTO classdate, sessions.day INTO sessionday

Oracle trigger failed -ORA-04098

I have a table for which i have written a trigger:
CREATE OR REPLACE TRIGGER ac01_control_trigg
AFTER INSERT ON ac1_control_test
FOR EACH ROW
DECLARE
BEGIN
IF :NEW.cur_pgm_name = 'LSN'
AND :NEW.nxt_pgm_name ='MD'
AND :NEW.file_status='RD' THEN
INSERT INTO ac1_control_test
(FILE_NAME, FILE_PATH,FILE_STATUS,CUR_PGM_NAME,NXT_PGM_NAME)
VALUES
(:NEW.FILE_NAME, :NEW.FILE_PATH,:NEW.FILE_STATUS,:NEW.CUR_PGM_NAME,'MD_MPS');
END IF;
END ac01_control_trigg;
when i am trying to insert into the table i am getting an error below!
ORA-04098: trigger 'CNGDB18.AC01_CONTROL_TRIGG' is invalid and failed re-validation
could anybody please help?
also when i compile the trigger in Toad,i am getting compile errors as below:
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/65 PLS-00049: bad bind variable 'NEW_FILE_STATUS'
but what is the wrong with this?
and what does this error mean?
EDIT: Now that we see the message, the solution is easy :)
Use :NEW.file_status='RD' instead of:new_file_status='RD'
Your trigger object is invalid (there is a problem with the code).
Test this with:
SELECT object_name, status
FROM user_objects
WHERE object_name = 'AC1_CONTROL_TRIGG';
Should return:AC1_CONTROL_TRIGG INVALID
You can try the following in SQL*Plus to get a description of the error:
ALTER TRIGGER ac1_control_trigg COMPILE;
SHOW ERROR TRIGGER ac1_control_trigg;
Using TOAD, you can just type these two lines into an editor, select them and use Editor>Execute SQL via SQL*Plus.