Facing difficulty in removing the apostrophe in MySQL stored procedure?

MySQLMySQLi Database

To remove apostrophe, replace it. For this, you can use REPLACE(). Following is the syntax −

SET anyVariableName = REPLACE(yourVaribleName , '\'', '');

To understand the above syntax, let us create a stored procedure to remove the apostrophe in MySQL −

mysql> DELIMITER //
mysql> CREATE PROCEDURE remove_Apostrophe(IN Value VARCHAR(200))
   BEGIN
      SET Value = REPLACE(Value , '\'', '');
      SELECT CONCAT("AFTER REMOVING APOSTROPHE THE STRING IS= ", Value);
   END
   //
Query OK, 0 rows affected (0.15 sec)
mysql> DELIMITER ;

Call the stored procedure using CALL command −

mysql> CALL remove_Apostrophe("Introduction to My'SQL");

This will produce the following output −

+----------------------------------------------------------------+
| CONCAT("AFTER REMOVING APOSTROPHE THE STRING IS= ", Value)     |
+----------------------------------------------------------------+
| AFTER REMOVING APOSTROPHE THE STRING IS= Introduction to MySQL |
+----------------------------------------------------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.01 sec)
raja
Published on 22-Aug-2019 10:26:46
Advertisements