Tip: Add double quotes and commas to a column of data in excel for in() query in sql

Supporting video notes: https://www.bilibili.com/video/BV1iG4y1U7r2


background

That is, we need to give an excel, and we need to use a certain column as a condition to query the database, delete data or change data.
It is not worth writing code to parse excel for such a small requirement, just write sql directly.
You can use in(...) to query by adding single or double quotation marks at the beginning and end.

reference

excel-Add double quotes and commas to a column of data, escape in the excel formula

Escaping and handling of special characters in Excel

Three methods of Excel string splicing, the last one is the most powerful

Method 1: excel ctrl+e smart fill universal shortcut key

Method 2: Excel uses the formula & or CONCAT to concatenate strings

  • Knowledge point: Two quotation marks are used to represent a quotation mark in an excel formula . EXCEL stipulates that a pair of double quotation marks "" is the text delimiter, and two pairs of double quotation marks are equivalent to the two outer double quotation marks as the text delimiter, and the inner two double quotation marks are equivalent to one double quotation mark.

  • Single quotes can be entered directly

  • Strings need to add double quotes, cells do not

  • ="'"&A2&"'," add single quotes, press Enter to take effect, drag the bottom right corner to fill

  • =""""&A2&"""," with double quotes

  • =CONCAT("""",A2,""",") CONCAT function

    image-20230204122121529

Method 3: Notepad++ replaces the text editor

  • 1. Create a new file ( ctrl+n ) and copy the column data of excel

  • 2. ctrl+f to open the query and replace window

  • 3. Find target: \r\n

  • 4. Replace with: ",\r\n"

  • 5. The search mode should be extended (\n,\r)

  • 6. Click Replace All

    image-20230204122652542

Method 4: idea regular replacement

  • 1. Create a temporary file ( Ctrl + Alt + Shift + Insert , any file type is fine, scratch for drafting), copy the data over

  • 2.ctrl + r, open the replacement window, check Regex

  • 3. Find the target: \n is a little different from notepad++, there is no need for \r\n, in regular expressions, \n means to match all newline characters

  • 4. Replace with: ",\n"

  • 5.Replace all

  • References: IDEA uses regular expressions to quickly replace code

    image-20230204124629068

Method 5: idea multi-line editing

  • 1. Alt + left click to drag, select the header, and enter "

  • 2. After the input is complete, press end to jump to the end of the line, enter ",

  • 3. In addition to pressing end, you can also press ctrl + w (extended selection, word by word expansion, can be used to delete the serial number in front of each line), then press to jump to the end of the first word, enter ",

  • 4. Press esc to exit multi-line editing mode

  • Reference material: Idea shortcut key shortcut multi-line editing
    image-20230204125406658

Guess you like

Origin blog.csdn.net/weixin_44174211/article/details/128880864