SQL Escape/Unescape - Escape SQL Special Characters Online
Double the single quotes in text for a SQL string literal, with backslash escaping for MySQL, or turn escaped text back into the original.
How to Escape SQL Special Characters - Step by Step Guide
Input Your SQL String
Let's get your SQL string ready for escaping! Whether you're working with MySQL, PostgreSQL, SQL Server, Oracle, or SQLite user input, data imports, or dynamic queries, you have several convenient options:
Example: Unescaped Input
Here's text with special characters that need escaping:
John's laptop costs $1,200
Automatic Escaping
The output updates a moment after you stop typing. What changes depends on the Database option:
Example: Escaped Output
The same text, now properly escaped for SQL:
John''s laptop costs $1,200
Use Escaped String in Your Query
Get your escaped string ready for safe SQL usage! Multiple options make it easy to integrate:
Example: Using Escaped String in SQL
Here's how to use the escaped string in a query:
INSERT INTO products (name, description) VALUES ('Laptop', 'John''s laptop costs $1,200');
Frequently Asked Questions
Why do I need to escape SQL strings?
A single quote ends a SQL string literal, so text like O'Brien breaks the statement, and text written by an attacker can close the string and add its own SQL. Escaping makes the database read every character as part of the value. For anything that runs in an application, parameterized queries (prepared statements) are the real fix, because the value never becomes part of the SQL text at all. Use this page for hand-written scripts, seed data and one-off queries.
What characters get escaped?
With PostgreSQL, SQL Server, SQLite or Oracle selected, only the single quote changes: ' becomes ''. With MySQL / MariaDB selected, backslashes are doubled as well (\ becomes \\) and a NUL character is written as \0, because MySQL treats the backslash as an escape character by default. Double quotes are left alone, since inside '...' they are ordinary characters. Numbers, accents, emoji and line breaks are not touched.
Which database option should I pick?
Pick MySQL / MariaDB for those two databases in their default mode. For PostgreSQL, SQL Server, SQLite and Oracle pick the other option: they keep backslashes as plain characters, so doubling them would store two backslashes instead of one. If your MySQL server runs with NO_BACKSLASH_ESCAPES, use the PostgreSQL option too.
Does the output go inside quotes?
Yes. The result is the inside of a string literal, so wrap it in single quotes yourself: VALUES ('O''Brien'). It is not meant for identifiers such as table or column names, which use double quotes, backticks or square brackets depending on the database.
Can I unescape SQL strings too?
Switch Mode to Unescape and paste the text from between the quotes. It turns '' back into ' and, with the MySQL option, reads backslash sequences such as \\, \n and \0 the way MySQL does. Escaping and then unescaping with the same option gives back exactly the text you started with.
Is my text sent anywhere?
No. Escaping runs in your browser, so nothing you paste or upload reaches our server, and there is no sign-up.
Related Tools
SQL Formatter
Format and beautify SQL queries with proper indentation and syntax highlighting
SQL Beautifier
Beautify and format SQL code with customizable style options
SQL Fixer
Fix broken SQL queries automatically, repair syntax errors, and validate SQL structure
SQL Minifier
Minify and compress SQL queries by removing whitespace and comments
SQL Validator
Validate SQL syntax and detect errors in your queries
SQL to JSON
Convert SQL query results to JSON format