Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

trigger doesn't show dbms_output

AhmetMelihApr 11 2016 — edited Apr 11 2016

Hello. I created trigger. and I want when I update table, it works and show results which written in dbms_output function in trigger.

SQL> set serveroutput on;

SQL> CREATE OR REPLACE TRIGGER farechanges AFTER UPDATE ON tickets FOR EACH ROW

DECLARE

cname varchar2(25);

origname varchar2(25);

destname varchar2(25);

BEGIN

    select origin into origname from route where route_id=:Old.route_id;

    select destination into destname from route where route_id=:Old.route_id;

    select name into cname from buscompanies where bus_id=:Old.bus_id;

    dbms_output.put(cname || ' (' || origname || '->' || destname || '):');

    dbms_output.put(' New Fare: ' || :New.fare ||',');

    dbms_output.put(' Old Fare: ' || :old.fare ||',');

    dbms_output.put(' Change Amount: ' ||  (( :New.fare-:old.fare ) / :old.fare) * 100 );

END;

/  2    3    4    5    6    7    8    9   10   11   12   13   14   15 

Trigger created.

SQL> update tickets set fare=23.32 WHERE ROUTE_ID=1 AND BUS_ID=1;

1 row updated.

I can'T see any result. I want the result as

SQL> update tickets set fare=23.32 WHERE ROUTE_ID=1 AND BUS_ID=1;

A Bus (Ankara -> Bursa) New Fare : 23.32 Old Fare: 13.32 Change Amount: 100

1 row updated.

This post has been answered by Vysakh Suresh - 3035408 on Apr 11 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 9 2016
Added on Apr 11 2016
8 comments
2,183 views