Home > database >  MySQL Trigger on After Update a certain column, How to print a line without raise application error?
MySQL Trigger on After Update a certain column, How to print a line without raise application error?

Time:05-23

I am new to MySQL and now I am learning about trigger. I have one table, table1. I am trying to create a trigger for every update executed in address column, I would also like to print a line without raising application error. Here is how my table looks like:

create table table1(
  2  ID varchar(9),
  3  Name char(25),
  4  DOB date,
  5  address varchar(20)
  6  )
  7  ;

My trigger does not seem to print any output when I update the address.

CREATE OR REPLACE TRIGGER TR_UPDATE_ADDRESS
  2  AFTER UPDATE of address ON table1
  3  BEGIN
  4  dbms_output.put_line('Address Column is Updated Successfully');
  5  END;
  6  /

Update:

 update table1 set address =  '東京' where ID = '144131214';

Output:

1行が更新されました。 (1 row(s) updated).

CodePudding user response:

In order to use DBMS_OUTPUT.PUT_LINE you need to execute SET SERVEROUTPUT ON first - to enable printing the buffer to the screen.

Example:

koen>update table1 set address = 'Belgium';

1 row updated.

koen>set serveroutput on size 999999
koen>update table1 set address = 'Belgium';
Address Column is Updated Successfully


1 row updated.

koen>
  • Related