0

I have to update many database records that have two columns; id and content.

The problem is that content can contain any number of words and special characters and I want MySQL to understand, that everything in the field, between the very first and last double quotes ("), is an string, e.g.:

(1823423, "blabla <script type"something/something> somettext '_' " 
 + " and more text + more special characters")

As I have about 5k similar records to update and this script can't be changed like adding escape characters (\"), because it would stop working.

Flygenring
  • 3,818
  • 1
  • 32
  • 39
harcotlupus
  • 109
  • 1
  • 9
  • So what is the problem? Can you add the special characters? Maybe use `CHAR(ascii number)` – Juan Carlos Oropeza Nov 23 '17 at 13:37
  • Is this sample code ``(1823423, "blabla – Laiso Nov 23 '17 at 13:38
  • Problem is, that mysql things that column ends after second " from text, which is just small part of whole column content – harcotlupus Nov 23 '17 at 13:39
  • check this https://stackoverflow.com/questions/4803354/how-do-i-insert-a-special-character-such-as-into-mysql – Amol Raje Nov 23 '17 at 13:40
  • @Laiso it's a part of example string that i want to insert into DB – harcotlupus Nov 23 '17 at 13:40
  • @Amol Raje As i mentioned in question, if I put anything that negates special character inside script it would stop working.. so i can't just \ all special characters. I just want to show sql that everything that is between first " and last " is a string – harcotlupus Nov 23 '17 at 13:42
  • you need `mysql_real_escape_string()` like function which is in php it will handle the special characters. – Amol Raje Nov 23 '17 at 13:45
  • @harcotlupus Please take a look at this documentation https://dev.mysql.com/doc/refman/5.7/en/string-literals.html – Laiso Nov 23 '17 at 13:45

1 Answers1

0

You need use CONCAT and escape the caracters with \

I guess you need something like this

SQL DEMO

SELECT CONCAT("blabla script type\"something/something\"> somettext '_' " ,
              " and more text + more special characters") as t
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118