Ví dụ handler CONTINUE hiển thị thông báo nhưng chạy tiếp:
mysql> DELIMITER //
mysql> CREATE PROCEDURE Insert_Studentdetails(
S_Studentid INT, S_StudentName VARCHAR(20), S_Address VARCHAR(20))
-> BEGIN
-> DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT 'Got an error';
-> INSERT INTO Student_detail (Studentid, StudentName, Address)
-> VALUES(S_Studentid, S_StudentName, S_Address);
-> SELECT * FROM Student_detail;
-> END //
Query OK, 0 rows affected (0.19 sec)
Chèn lần 1 (id=100): thành công
mysql> CALL Insert_Studentdetails(100, 'Gaurav', 'Delhi'); +-----------+-------------+---------+ | Studentid | StudentName | address | +-----------+-------------+---------+ | 100 | Gaurav | Delhi | +-----------+-------------+---------+
Chèn lần 2 (id=101): thành công
mysql> CALL Insert_Studentdetails(101, 'Raman', 'Shimla'); +-----------+-------------+---------+ | Studentid | StudentName | address | +-----------+-------------+---------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | +-----------+-------------+---------+
Chèn trùng (id=101 lại):
mysql> CALL Insert_Studentdetails(101, 'Rahul', 'Jaipur'); +--------------+ | Got an error | +--------------+ +-----------+-------------+---------+ | Studentid | StudentName | address | +-----------+-------------+---------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | +-----------+-------------+---------+
Hiển thị 'Got an error' VÀ vẫn chạy SELECT * trả về dữ liệu hiện có.