স্টোরড প্রোসিডিউরে এক্সসেপশন হলে সঠিক এরর মেসেজ দেওয়া জরুরি। MySQL এরর মেসেজ ফেলে এক্সিকিউশন চালিয়ে রাখার হ্যান্ডলার দেয়। প্রাইমারি কি কলামে ডুপ্লিকেট ভ্যালু ইনসার্ট করার উদাহরণ:
উদাহরণ
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)
প্রোসিডিউরটি আহ্বান করলে ডুপ্লিকেট 'studentid' ইনসার্ট করলে 'got an error' মেসেজ দেখিয়ে এক্সিকিউশন চালিয়ে রাখবে:
mysql> Delimiter ; mysql> CALL Insert_Studentdetails(100, 'Gaurav', 'Delhi'); +-----------+-------------+---------+ | Studentid | StudentName | address | +-----------+-------------+---------+ | 100 | Gaurav | Delhi | +-----------+-------------+---------+ 1 row in set (0.11 sec) Query OK, 0 rows affected (0.12 sec) mysql> CALL Insert_Studentdetails(101, 'Raman', 'Shimla'); +-----------+-------------+---------+ | Studentid | StudentName | address | +-----------+-------------+---------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | +-----------+-------------+---------+ 2 rows in set (0.06 sec) Query OK, 0 rows affected (0.12 sec) mysql> CALL Insert_Studentdetails(101, 'Rahul', 'Jaipur'); +--------------+ | Got an error | +--------------+ | Got an error | +--------------+ 1 row in set (0.03 sec) +-----------+-------------+---------+ | Studentid | StudentName | address | +-----------+-------------+---------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | +-----------+-------------+---------+ 2 rows in set (0.04 sec) Query OK, 0 rows affected (0.05 sec) mysql> CALL Insert_Studentdetails(103, 'Rahul', 'Jaipur'); +-----------+-------------+---------+ | Studentid | StudentName | address | +-----------+-------------+---------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | | 103 | Rahul | Jaipur | +-----------+-------------+---------+ 3 rows in set (0.08 sec) Query OK, 0 rows affected (0.10 sec)