i have two tables named as childs and parent.
create table parent(
wallet_id NUMBER generated always as identity,
amount int,
customer_id int,
primary key(wallet_id),
Foreign key (customer_id) REFERENCES childs(customer_id)
);
create table childs(
customer_id number generated always as identity,
name varchar2 (255)
);
Now what i wanted to achieve was to get name from childs , and assign a wallet_id to childs in parent table as parent table has a foreign key to customer_id. For this purpose i created a trigger.
create or replace
TRIGGER TRIGGER1
AFTER INSERT ON CHILDS
Declare
id int;
BEGIN
select MAX(customer_id) into id FROM childs;
insert into parent (customer_id ) values ( id );
END;
Now trigger is created but when i insert value in childs,
insert into childs(names) values ('jarral');
Now following error appears:
SQL Error: ORA-04098: trigger 'SYSTEM.TRG' 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.
How can i solve that?
childsthe parent ofparent? And your definition is missing a primary/unique key for the FK onparentto refer to, and thesystemschema is reserved for Oracle internal objects that you are not supposed to go near. Aside from that, the trigger creates without error. Yourinsertstatement refers to a column callednamesthat doesn't exist, but otherwise runs fine. - William Robertson