SQL query for a carriage return in a string and ultimately removing carriage return

后端 未结 10 1508
-上瘾入骨i
-上瘾入骨i 2020-12-04 17:37

SQL query for a carriage return in a string and ultimately removing carriage return

I have some data in a table and there are some carriage returns in places where I

相关标签:
10条回答
  • 2020-12-04 18:00

    The main question was to remove the CR/LF. Using the replace and char functions works for me:

    Select replace(replace(Name,char(10),''),char(13),'')
    

    For Postgres or Oracle SQL, use the CHR function instead:

           replace(replace(Name,CHR(10),''),CHR(13),'')
    
    0 讨论(0)
  • 2020-12-04 18:01

    this will be slow, but if it is a one time thing, try...

    select * from parameters where name like '%'+char(13)+'%' or name like '%'+char(10)+'%'
    

    Note that the ANSI SQL string concatenation operator is "||", so it may need to be:

    select * from parameters where name like '%' || char(13) || '%' or name like '%' || char(10) || '%'
    
    0 讨论(0)
  • 2020-12-04 18:06

    this works: select * from table where column like '%(hit enter)%'

    Ignore the brackets and hit enter to introduce new line.

    0 讨论(0)
  • 2020-12-04 18:12

    Something like this seems to work for me:

    SELECT * FROM Parameters WHERE Name LIKE '%\n%'
    
    0 讨论(0)
  • 2020-12-04 18:13

    This also works

    SELECT TRANSLATE(STRING_WITH_NL_CR, CHAR(10) || CHAR(13), '  ') FROM DUAL;
    
    0 讨论(0)
  • You can also use regular expressions:

    SELECT * FROM Parameters WHERE Name REGEXP '\n';
    
    0 讨论(0)
提交回复
热议问题