i am trying to get a trigger to display an entire table called records_t upon a deletion, insertion or update.
so i wrote this
create or replace trigger display_rec
after insert or update or delete on records_t
for each row
declare
cursor cur is
select recno, recdate, recamt from records_t;
begin
loop
DBMS_OUTPUT.PUT_LINE (c.recno || ' ' || c.recdate || ' ' || c.recamt);
end loop;
end;
when I run it I get an error that the records table is mutating. please help
You can't access rows from table that is just being modified in a row-level trigger because ... well, as you know, table is mutating.
Then, you said that trigger whose code you posted raised an error. No way, it is invalid and can't be compiled (so it can't work) because
Generally speaking, it isn't the best idea to claim something and post code that doesn't support those claims.
If you switched to a statement-level trigger and fixed code so that it is actually valid, then it does what you wanted - displays contents of the table:
Although it now works, its usage is doubtful. Unless you (or end users) modify table using a tool that is capable of displaying
dbms_output.put_linecontents (such as SQL*Plus or SQL Developer or some other GUI tools), you won't see anything. For example, if you updated table via Oracle Forms application or Oracle Apex one, trigger would silently display output to nothing. It wouldn't fail, but you wouldn't see what it wrote.Therefore, just being curious: what is its real purpose?