Loading SQL Escape...
Please wait a moment

How to Escape SQL Special Characters - Step by Step Guide

Step 1

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:

•
Paste directly: Copy your text with special characters and paste it into the input editor
•
Upload a file: Click "Upload" to select a text file from your computer
•
Try the sample: Click "Sample" to load example text and see how escaping works

Example: Unescaped Input

Here's text with special characters that need escaping:

John's laptop costs $1,200
Step 2

Automatic Escaping

The output updates a moment after you stop typing. What changes depends on the Database option:

•
Single quotes, always: ' becomes '', so the quote stays part of the value instead of ending the string
•
Backslashes, MySQL / MariaDB only: \ becomes \\ and a NUL character becomes \0. Without this, input such as a\'; DROP TABLE y; -- could close a MySQL string early
•
Everything else stays as typed: double quotes, numbers like 8901240544102066246 or 00501, accents, emoji and line breaks

Example: Escaped Output

The same text, now properly escaped for SQL:

John''s laptop costs $1,200
Step 3

Use Escaped String in Your Query

Get your escaped string ready for safe SQL usage! Multiple options make it easy to integrate:

•
Copy to clipboard: One-click copying for quick use in your SQL queries
•
Match the database: Use the MySQL option for MySQL and MariaDB, the other one for PostgreSQL, SQL Server, Oracle and SQLite
•
Use in INSERT/UPDATE: Handy for seed data and hand-written scripts. For user input in an app, use parameterized queries instead

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.