How to remove text between 2 characters using query in MYSQL

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

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

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


        
4条回答
  •  深忆病人
    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)),'')
    

提交回复
热议问题