Facing difficulty in removing the apostrophe in MySQL stored procedure?



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)
Updated on: 2019-08-22T10:26:46+05:30

291 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements