There are many line breaks and carriage returns in MySQL data. The Java intermediate interview contains answers

No hair loss Xiaoyi 2021-08-31 20:07:18 阅读数:831

line breaks carriage returns mysql
  • A newline :CHAR(10) = "\n"

  • A carriage return : CHAR(13) = "\r"

?? stay MySQL in , A carriage return 、 Line breaks belong to char type , Put it in varchar In the middle of the day , stay navcat It will not be displayed on the plug-in , Need to be in mysql Terminals and navcat Only by contrast can we see ( Pit ~)

navcat The plug-in is shown below :

 Insert picture description here

MySQL The terminal displays as follows :

( A carriage return \r It also causes data results to be returned directly , Only part of it is shown ,MySQL You let me say what you're good about ???)


mysql> select * from `LOL`;
+----+-------------------------------+-----------+-------+
| id | hero_title | hero_name | price |
+----+-------------------------------+-----------+-------+
| 1 | D The shadow of the blade | Tyrone | 6300 |
| 2 | X Swift scout | Timo | 6300 |
| 8 | A newline
A newline
A newline | A newline | 450 |
A carriage return | A carriage return | 450 |
+----+-------------------------------+-----------+-------+
4 rows in set (0.00 sec)

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

 1、 How to remove line breaks 、 A carriage return

============================================================================

If conditions permit , It is recommended to clear the newline character and carriage return character directly through the statement , as follows :

Remove "hero_title" All line breaks in the column ( Either way )


-- Remove "hero_title" All line breaks in the column ( Either way )
update `LOL` set hero_title = REPLACE(hero_title, '\n', '');
update `LOL` set hero_title = REPLACE(hero_title, char(10), '');

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

– Remove "hero_title" All carriage returns in the column ( Either way )


-- Remove "hero_title" All carriage returns in the column
update `LOL` set hero_title = REPLACE(hero_title, '\r', '');
update `LOL` set hero_title = REPLACE(hero_title, char(13), '');

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

 2、SELECT How to ignore " A newline 、 A carriage return " The query

========================================================================================

?? If conditions do not permit , Such as customers “ Very excited ” And yelled at you : You can't move the data in the library !… I smiled. ~

?? Then what shall I do? ? It can be modified by SQL To filter out line breaks 、 A carriage return , But to a certain extent, it will affect the query efficiency , And a lot of code to change , Do you know .

?? Remember what Mr. Lu Xun said : Where there is oppression , Where there has to be resistance !

 Insert picture description here

Examples are as follows :


-- Ignore line switch queries
# Last
2020 Years passed in a hurry , We have ushered in a new year , The Internet is developing so fast , Technology changes with each passing day , Update iteration has become the pronoun of this era , The technology system will be more and more robust ,JVM As a necessary skill for job hopping companies , If you haven't mastered , Not to mention the new technology that was updated later .
![](https://s2.51cto.com/images/20210826/1629929159635077.jpg)
** more JVM Interview arrangement :**
![](https://s2.51cto.com/images/20210826/1629929159422357.jpg)
**[ Click here to download for free “ Million level ”「JVM note 」](https://gitee.com/vip204888/java-p7)**
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
版权声明:本文为[No hair loss Xiaoyi]所创,转载请带上原文链接,感谢。 https://car.inotgo.com/2021/08/20210826061220239x.html