I am facing this error.
I have two Schema Schema A and Schema B
Schema B contains a table my_table in which values are being Inserted.
There is also a triggger my_trigger written for my_table in schemaB for each row
CREATE OR REPLACE TRIGGER schemaB.my_trigger
ON schemaA.my_table
FOR EACH ROW
BEGIN
IF INSERTING THEN
schemaA.my_package.my_procedure (:NEW.field_A,NEW.field_B, :NEW.field_C);
END IF;
EXCEPTION
WHEN OTHERS THEN
Insert into my_log(DBMS_UTILITY.format_error_stack,sysdate);
END my_trigger;
/ AFTER INSERT
This trigger written on my_table of schemaB is calling a procedure which is present in Schema A.
However when the trigger is being fired I am getting the below error in my logs
ERROR: ORA-04061: existing state of package "schemaA.my_package" has been invalidated
ORA-04065: not executed, altered or dropped package "schemaA.my_package"
ORA-06508: PL/SQL: could not find program unit being called: "schemaA.my_package"
ORA-06512: at "schemaB.my_trigger", line 17 10/1/2015 6:38:07 PM
Also the procedure in schemaA is declared as PRAGMA_AUTONOMOUS_TRANSACTION
Is this some grants issue as i checked all the grants has been given, I have checked dependencies of the both trigger and procedure
and all seems to valid. Can you kindly help?
I have tried using Pragma serially_reusable in the calling package but still giving me same error
Many thanks
Possible issues you can have is:
The package/procedure you are calling is invalid
check this query whether you have an entry of your package or objects used in your package in this all_objects view
select * from all_objects where status = 'INVALID' and owner = 'SCHEMA_NAME';
Check your package is having global variables? if yes then check if those variable is not being changed by any other session
run below script to compile all the objects in your schema
begin
dbms_utility.compile_schema('SCHEMA_NAME',false);
end;
Last option if none of the above works then remove all the procedures/function from your package, add new function and try to run your function from the trigger. check if this works then your package is in special lock. after adding a new function it's state will be valid again and then you can add all your actual funcs/procs and remove the newly added one.
Related
I am trying to create a trigger named transaction_type_af_insert that is triggered whenever a new record is inserted into ransaction_type table. This trigger will insert the new type and action into the table transaction_type_log_history after the insertion of transaction type details. The action name in the affected log table transaction_type_log_history is 'After_Insert_transaction_type'.
But facing below error:
Warning: Trigger created with compilation errors.
insert into transaction_type(id,type)values(22,'Credit Card')
*
ERROR at line 1:
ORA-04098: trigger 'P12097.TRANSACTION_TYPE_AF_INSERT' is invalid and failed
re-validation
Please help me resolve the issue
CREATE TRIGGER transaction_type_af_insert
AFTER INSERT
ON transaction_type FOR EACH ROW
DECLARE
type varchar(30)
action varchar(30)
BEGIN
UPDATE transaction_type_log_history
SET action = 'After_Insert_transaction_type'
WHERE transaction_type.id = transaction_type_log_history.id;
END;
You can query the user_errors view to see what is actually wrong; some clients let you show errors as a shortcut after you create the object (SQL Developer, SQLcl, SQL*Plus..) and see the 'Warning: Trigger created with compilation errors' message. With your current code that will say something like:
PLS-00103: Encountered the symbol "(" when expecting one of the following:
; is default authid as force under accessible
type is a reserved word so you can't use that for a local variable name - it's expecting you to be declaring a record type. Changing the name of that variable reveals the next error:
PLS-00103: Encountered the symbol "ACTION" when expecting one of the following:
:= ; not null default character
which is because you don't have semicolons after your declarations.
Fixing that still gets 'ORA-00904: "TRANSACTION_TYPE"."ID": invalid identifier' because your update statement doesn't include the transaction_type table. You can use correlation names to refer to data in the original table row statement the trigger fired against, using :new by default; so this now compiles:
CREATE OR REPLACE TRIGGER transaction_type_af_insert
AFTER INSERT ON transaction_type
FOR EACH ROW
DECLARE
l_type varchar2(30);
l_action varchar2(30);
BEGIN
UPDATE transaction_type_log_history
SET action = 'After_Insert_transaction_type'
WHERE transaction_type_log_history.id = :new.id;
END;
/
db<>fiddle
You aren't actually using either of the the two locally declared variables so you can remove those and the declare keyword.
You also seem to be trying to update the history table instead of inserting a new row there, which the problem statement seems to suggest you should be doing.
I'm trying to execute a Merge procedure Iv'e created but I encounter the following error:
Could not get schema Object:java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
I read in forum about the error and I made sure I'm on the right scheme.
In addition, the merge query works properly.
any suggestion?
procedure
create or replace procedure insert_or_update_Account
IS
BEGIN
MERGE INTO CRMAS_ODS_RAW_DATA.ACCOUNT T
USING CRMAS_ODS_RAW_DATA.ACCOUNT_TMP S
ON ( T.TCCID=S.TCCID)
WHEN MATCHED THEN
UPDATE
SET
T.BATCH_ID =S.BATCH_ID ,
T.SOURCE_SYSTEM =S.SOURCE_SYSTEM ,
T.UPDATE_DATE =S.UPDATE_DATE ,
T.MLI_LOCALID =S.MLI_LOCALID
WHERE
T.BATCH_ID <>S.BATCH_ID OR
T.SOURCE_SYSTEM <>S.SOURCE_SYSTEM OR
T.MLI_LOCALID <>S.MLI_LOCALID
WHEN NOT MATCHED THEN
INSERT (T.BATCH_ID,T.SOURCE_SYSTEM,T.UPDATE_DATE,T.TCCID,T.MLI_LOCALID,T.MLI_LOCALSYSTEMNAME)
VALUES (S.BATCH_ID,S.SOURCE_SYSTEM,S.UPDATE_DATE,S.TCCID,S.MLI_LOCALID,S.MLI_LOCALSYSTEMNAME);
commit;
END insert_or_update_Account;
The procedure owner should be granted privileges on CRMAS_ODS_RAW_DATA.ACCOUNT table directly, not via role.
The fact that MERGE works in SQL (but not in PL/SQL) sounds exactly like that.
Any one can help on the below issue.
Thanks in advance.
I am updating a Table ACC_STATUS for Id 100
Current Value of Status Column is 0.
UPDATE ACC_STATUS
SET STATUS = 1
WHERE ID = 100;
After Update I am calling a Procedure, pro_do_other_things, which is in another Schema.
There is a SELECT From Table ACC_STATUS in this Procedure - pro_do_other_things. The result is not showing the updated value always. In some cases it shows the New Updated Value and in some other cases Old Value.
Please not that both Update Statement and Call to Procedure are happening in the Same Transaction as below.
BEGIN
UPDATE ACC_STATUS
SET STATUS = 1
WHERE ID = 100;
OTHER_SCHEMA.pro_do_other_things;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END;
Could anyone please explain why it is happening so?
By default the procedures are defined with definer rights (same as AUTHID DEFINER, see https://docs.oracle.com/database/121/DBSEG/dr_ir.htm).
It means they are executed with the privileges of the schema they are defined in.
If there is a table without schema referenced in such stored procedure, the table is resolved as table from the definer's schema.
In your case the OTHER_SCHEMA.pro_do_other_things makes select from OTHER_SCHEMA.acc_status, not from acc_status in your schema.
When you define the procedure as AUTHID CURRENT_USER, then a referenced table without schema will be resolved as a table from the invoker's schema.
In this case the OTHER_SCHEMA.pro_do_other_things would make select from acc_status in your schema.
Note: When you always want to reference the same table regardless the invoker, you have to use it explicitly with schema or you have to create and use a synonym.
I have a view to fetch list of my project specific packages from all_objects in Oracle DB, which will fetch the name, status, created and last DDL for all objects with wildcard operator specific to my project requirement.
CREATE OR REPLACE FORCE VIEW ALL_XYZ_PACKAGES_VW
AS
SELECT object_name,status, object_type,created,last_ddl_time
FROM all_objects
WHERE object_name LIKE 'XYZ_%'
AND object_type IN ('PACKAGE', 'PACKAGE BODY');
And my requirement is to fire a trigger which sends an email notification when any of my package gets Invalid due to some DB Link missing or dependent object is missing or any wrong code deployed with logical errors.
So following is the trigger i have created:
CREATE OR REPLACE TRIGGER notify_invalidobjects_trigger
INSTEAD OF UPDATE ON ALL_XYZ_PACKAGES_VW
FOR EACH ROW
BEGIN
IF (:NEW.STATUS = 'INVALID') THEN
DBMS_OUTPUT.PUT_LINE ('Following mentioned Package is in INVALID state: '|| :OLD.OBJECT_NAME); -- Email notification part will e written here
ELSE
DBMS_OUTPUT.PUT_LINE ('In Else Block');
END IF;
END;
/
Issue:
1) When i am manually updating the package status as INVALID in my view with an update statement, trigger is getting fired.
BUT when the package is automatically getting Invalid, when i am making some dependent object as Invalid or by wrong code deployment,
TRIGGER IS NOT GETTING FIRED EVEN THE STATUS IS
GETTING INAVLID AUTOMATICALLY IN MY VIEW AND ALL_OBJECTS.
Could any one suggest me what i need to check or update in code.
Note: I thought of using After Update trigger, but its not allowing me to use the same on views.
The trigger on the view will not fire because the view is not updated. Your view is no more and no less then a stored select statement. If you don't need "live response" I'd suggest to just change to a procedure for query all_objects and send the mail and run it via job.
I'm working on adding a database project in VS2010. I created a SQL 2008 DB Project, pointed at the development server, and it seems to have generated all of the appropriate schema objects. However, all of the CREATE TRIGGER scripts have the following error:
SQL03120: Cannot find element referenced by the supporting statement
Googling that error message doesn't return much, and seems to point to scripts using ALTER instead of CREATE which isn't the case here. This is an example of one of the scripts:
CREATE TRIGGER [TR_t_TABLE_TRIGGERNAME] ON [content].[t_TABLE]
FOR INSERT
AS
BEGIN
IF ( SELECT COUNT(*) FROM inserted) > 0
BEGIN
DECLARE #columnBits VARBINARY(50)
SELECT #columnBits = COLUMNS_UPDATED() | CAST (0 AS BIGINT)
INSERT INTO [history].[t_TABLE]
(
....
)
SELECT
....
FROM inserted
END
END
GO
EXECUTE sp_settriggerorder #triggername = N'[Content].[TR_t_TABLE_TRIGGER]', #order = N'last', #stmttype = N'insert';
The line that Visual Studio is attributing the error to is the last line executing the system proc. What stands out to me is that none of the object exist in the dbo schema. The table is in the Content schema and it has a matching table in the History schema. It would seem like the [Content] and [History] qualifiers would be resolvable though. Can't figure this one out...
Since this post comes up when you search for the above error on Google: another reason for this error is if you've got a stored procedure in a database project which specifies ALTER PROCEDURE rather than CREATE PROCEDURE.