How to remove text between 2 characters using query in MYSQL

前端 未结 4 1098
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 20:00

I have table with field called description which contains text like following

|Description                              |
|----------------------------------         


        
相关标签:
4条回答
  • 2021-01-15 20:10

    if you use php as your server side language you can use strip_tags function to remove tags.I hope it can help you.

    0 讨论(0)
  • 2021-01-15 20:33

    In short, you can't, you need a more advanced language like PHP. Your SQL query is not the place to be doing string manipulation.

    0 讨论(0)
  • 2021-01-15 20:33

    since this question is still in top google results, maybe the answer might help someone:

    a quick function that replaces the content between two characters. It should work with words as well, but I haven't test it with words. For deleting in the following string: "this is a [demo]"

    the string between [ and ] do:

    select deletestr("this is a [demo]" ,'[',']');

    and the function:

     CREATE DEFINER=`replace_with_your_db`@`%` 
    FUNCTION `deletestr` (`inputstr` TEXT CHARSET utf8, `fromstr` VARCHAR(10) CHARSET utf8, `tostr` VARCHAR(10) CHARSET utf8) RETURNS text CHARSET utf8
        NO SQL
    RETURN
    replace(inputstr,substr(inputstr, locate(fromstr,inputstr),locate(tostr,inputstr)-locate(fromstr,inputstr)+length(tostr)),'')
    
    0 讨论(0)
  • 2021-01-15 20:34

    How about REPLACE() using a wildcard to capture the unknown text between opening and closing brackets? http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

    0 讨论(0)
提交回复
热议问题