If you have a .csv file and you want to convert it into an SQL insert Query (be MySql, SQLite, Oracle), this can be done in just a few simple steps using Notepad++ Find and Replace with some Regular Expressions.

- Open the CSV (Comma Separated Values) file in Notepad++
- Enclose each data values in CSV file with Single Quotes.
- Forming the Query Go to Find and Replace,
- Now lets complete the Sql script.
- Notepad++ Editor alternatives for macOS
- How to add or remove bookmark on a line in Notepad++
- Notepad++ do not show CRLF characters
- Reduce the size of Tabs on Notepad++
- Delete blank lines in a file using Notepad++
- Fix: Notepad++ bottom status bar not visible
- Notepad++ Hex Editor
- How to show End of Line Characters in File using Notepad++
- [Tutorial] Write And Run Python Code In Notepad++ Editor
- How to install XML Tools Plugin Notepad++
- Customizing Notepad++ New Document Line Encoding: CR/LF/CR LF
- How to remove blank lines from a file using Notepad++
- Column Mode Editing in Notepad++
- Convert text to random case using Notepad++
- How to recover unsaved notepad file Windows 10
- How to delete all text after a character or string in Notepad++
- Setting up Cloud feature with Notepad++
- Install Notepad++ silently using Windows Powershell
- Using Document Map in Notepad++
- Enabling Notepad++ Dark Theme
- [Fix] Notepad++ tab not visible (hidden)
- Where are Notepad++ macros stored?
- Multiple line editing in Notepad++
- Alternatives for Notepad++ on Mac in 2021
- [Nopepad++] How to add text at end of each line
- Configure AWS Access ID and Secret Keys using CLI on Mac - AWS
- [Solutions] Android Error in an XML file: aborting build. Eclipse SDK - Android
- How to connect to Microsoft Exchange Online using PowerShell - Powershell
- How to use Autocomplete and Autosuggestion in Shell Commands - Bash
- 16: Find the largest element in a List - 1000+ Python Programs - Python-Programs
- How to reset Eclipse IDE Code Font - Eclipse
- How to create SharePoint List Item programmatically using C#.net - SharePoint
- Docker MySQL Compose File with Volume Example - Docker
Our Sample CSV Data :
1,data1,data-a,323
2,data2,data-b,324
3,data3,data-a,325
4,data4,data-b,326
5,data5,data-a,327
6,data6,data-b,328
Open Find and Replace by pressing "Ctrl + F", go to replace tab and,
Find : ,
Replace with : ','
Result :
1','data1','data-a','323
2','data2','data-b','324
3','data3','data-a','325
4','data4','data-b','326
5','data5','data-a','327
6','data6','data-b','328
Now data values are enclosed with Quotes, expect the row start and end. For this we need to use Regular Expression.
Find : ^
Replace : insert insert myTable values\('
^ is a regex character to add data at the start of each line in the file.
Keep in mind to select "Regular Expression" in Search Mode. \ (slash) is an escape character for braces in the regex.
Result :
insert insert myTable values('1','data1','data-a','323
insert insert myTable values('2','data2','data-b','324
insert insert myTable values('3','data3','data-a','325
insert insert myTable values('4','data4','data-b','326
insert insert myTable values('5','data5','data-a','327
insert insert myTable values('6','data6','data-b','328
Go to Find and Replace again and,
Find : $
Replace : '\);
Make sure that you select "Regular Expression" in Search Mode. \ (slash) is an escape character for braces in regex.
Result :
insert insert myTable values('1','data1','data-a','323');
insert insert myTable values('2','data2','data-b','324');
insert insert myTable values('3','data3','data-a','325');
insert insert myTable values('4','data4','data-b','326');
insert insert myTable values('5','data5','data-a','327');
insert insert myTable values('6','data6','data-b','328');
$ is a regex character to add data at the end of each line in file.
Thats it!! Our SQL Script is now ready!..
Note: Data may not be as simple as we have considered in our example. We may have Single Quotes (') in within itself, So in such cases, you need to first escape it by,
Find : '
Replace : ''
⚠️ Remember to move search mode in "Regular Expression" while using RegEx or else you may not get results.