Reputation: 41
I am using MySQL database. I want to insert data into it. But one column data contains special characters
. (backslash) I want to replace it with Double backslash
and then execute Insert query.
Can we do it using Insert Query?
While looking for the answer I came across
UPDATE your_table
SET your_field = REPLACE(your_field, '/', '//')
WHERE your_field LIKE '%articles/updates/%'
So it is possible use Replace
in Update query.
Can we do the same in insert query? Please Let me know if you can help me.
Upvotes: 1
Views: 52
Reputation: 1468
You can use the following:
REPLACE INTO table_name(column_name1,column_name2,…)
VALUES(value1,value2,…)
More info from:
http://www.mysqltutorial.org/mysql-replace.aspx
Upvotes: 1
Reputation: 2203
You can use a BEFORE INSERT TRIGGER
on your table
CREATE TRIGGER trigger_name
BEFORE INSERT
ON my_table
FOR EACH ROW
SET NEW.col_name = IF(NEW.col_name = '/','//',NEW.col_name);
Upvotes: 0