What would be a sql query to remove \n\r from the text?

后端 未结 7 1740
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 15:13

I am using MySQL. My data has a column called text, which uses the TEXT data type.

There are several newlines for each record in this column. I want to

相关标签:
7条回答
  • 2020-12-17 15:14

    Try this

    REPLACE(REPLACE(FIELD, '\n', ''), '\r', '')
    
    0 讨论(0)
  • 2020-12-17 15:14

    i've tried all said here but neither worked for me, my DB is IBM Informix, however i managed to solve the problem like this:

    UPDATE personas SET foto_path = SUBSTRING(foto_path FROM 1 FOR LENGTH(foto_path) - 1);
    

    Hope it helps other in similar situation.

    0 讨论(0)
  • 2020-12-17 15:18

    Try this one -

    CREATE TABLE table1(column1 TEXT);
    INSERT INTO table1 VALUES ('text1\r\ntext2
    text3');
    
    SELECT * FROM table1;
    --------
    text1
    text2
    text3
    
    UPDATE table1 SET column1 = REPLACE(column1, '\r\n', '');
    SELECT * FROM table1;
    --------
    text1text2text3
    
    0 讨论(0)
  • 2020-12-17 15:23

    The previous suggestions did not work for me. It only seems to work if I had actually typed the \r and \n text in as text. I found the following to work well -

    replace(replace([MyFieldName],char(13),''),char(10),'')
    

    I also created a calculated field in my table which uses this formula. That way I can just reference that field in areas of my program that were breaking with the original field contents.

    0 讨论(0)
  • 2020-12-17 15:28

    You can use REPLACE(text,'\n\r',' ') for it.

    0 讨论(0)
  • 2020-12-17 15:39

    Given suggestion i.e. REPLACE(REPLACE(DBField, '\n', ''), '\r', '') won't work if there are invisible html code like \n \r. For that you have to use char code.

    Example:

    REPLACE(REPLACE(REPLACE(DBField, CHAR(10), ''), CHAR(13), ''), CHAR(9), '')
    
    0 讨论(0)
提交回复
热议问题