Oracle 23.26SQLLab-verified · 2026-11-19

ORA-01756: quoted string not properly terminated

A string literal opened with ' was never closed where Oracle expected it.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-01756: quoted string not properly terminated

Jump to a cause

  1. 01An apostrophe inside the value (O'Brien)
  2. 02The closing quote is missing
  3. 03An apostrophe in a PL/SQL message string

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-19 · container image gvenzl/oracle-free:23-slim

ORA-01756 means a string that starts with ' has no matching closing '. Usually the closing quote is not really missing: an apostrophe inside the text closed the string early, and the rest of the line left an odd number of quotes.

In the test the output was only ERROR: and the message, with no line number and no * marker, so you have to find the quote yourself. Count the ' characters in the statement: the number must be even.

01An apostrophe inside the value (O'Brien)

In 'O'Brien' the apostrophe after O closes the string. Brien is left outside, and the final ' opens a new string that is never closed.

Inside a string, write an apostrophe as two quotes: 'O''Brien'. The alternative quoting q'[O'Brien]' also works. The check returned O'Brien for both, and the INSERT with 'O''Brien' stored O'Brien.

Setup
Setuprun as lab_a
CREATE TABLE customers (cust_id NUMBER PRIMARY KEY, cust_name VARCHAR2(30) NOT NULL);
OUTPUT
Table created.
Reproducerun as lab_a
INSERT INTO customers VALUES (1, 'O'Brien');
✕ ERROR
ERROR:
ORA-01756: quoted string not properly terminated
Help: https://docs.oracle.com/error-help/db/ora-01756/
Checkrun as lab_a
SELECT 'O''Brien' AS doubled, q'[O'Brien]' AS q_quote FROM dual;
OUTPUT
DOUBLED Q_QUOTE
------- -------
O'Brien O'Brien

1 row selected.

When the value comes from user input, use bind variables instead of building the SQL string. Then quotes in the data do not matter.

After the fixrun as lab_a
INSERT INTO customers VALUES (1, 'O''Brien');
SELECT cust_id, cust_name FROM customers;
✓ SUCCESS
1 row created.


   CUST_ID CUST_NAME
---------- ------------------------------
         1 O'Brien

1 row selected.

02The closing quote is missing

VALUES (1, 'Kim); has no ' after Kim, so everything up to the end, including );, is read as part of the string. The statement is not executed at all: the table still had 0 rows.

Adding the closing quote, 'Kim', makes the INSERT succeed.

Setup
Setuprun as lab_a
CREATE TABLE customers (cust_id NUMBER PRIMARY KEY, cust_name VARCHAR2(30) NOT NULL);
OUTPUT
Table created.
Reproducerun as lab_a
INSERT INTO customers VALUES (1, 'Kim);
✕ ERROR
ERROR:
ORA-01756: quoted string not properly terminated
Help: https://docs.oracle.com/error-help/db/ora-01756/
Checkrun as lab_a
SELECT COUNT(*) AS cnt FROM customers;
OUTPUT
       CNT
----------
         0

1 row selected.
After the fixrun as lab_a
INSERT INTO customers VALUES (1, 'Kim');
SELECT cust_id, cust_name FROM customers;
✓ SUCCESS
1 row created.


   CUST_ID CUST_NAME
---------- ------------------------------
         1 Kim

1 row selected.

03An apostrophe in a PL/SQL message string

DBMS_OUTPUT.PUT_LINE('Don't forget to commit'); has the same problem inside PL/SQL. The apostrophe in Don't ends the string, and the block fails with ORA-01756 before it runs.

For text with apostrophes, q'[Don't forget to commit]' is easier to read than doubling every quote. The block then printed Don't forget to commit.

Reproducerun as lab_a
SET SERVEROUTPUT ON
BEGIN
  DBMS_OUTPUT.PUT_LINE('Don't forget to commit');
END;
/
✕ ERROR
ERROR:
ORA-01756: quoted string not properly terminated
Help: https://docs.oracle.com/error-help/db/ora-01756/
Checkrun as lab_a
SELECT q'[Don't forget to commit]' AS msg FROM dual;
OUTPUT
MSG
----------------------
Don't forget to commit

1 row selected.

With q'[...]' the text may contain ' freely as long as it does not contain ]'. You can also use other delimiters such as q'{...}'.

After the fixrun as lab_a
SET SERVEROUTPUT ON
BEGIN
  DBMS_OUTPUT.PUT_LINE(q'[Don't forget to commit]');
END;
/
✓ SUCCESS
Don't forget to commit

PL/SQL procedure successfully completed.

FAQ

How do I put a single quote inside a string in Oracle?

Write it twice: 'O''Brien' gives O'Brien. Or use alternative quoting: q'[O'Brien]'. Both were checked in the test.

ORA-01756 does not show a line number. How do I find the problem?

Count the ' characters in the statement; the total must be even. Look first at values that contain apostrophes (names, English text) and at the end of each string.

Can I get ORA-01756 inside PL/SQL?

Yes. A text like 'Don't ...' in DBMS_OUTPUT.PUT_LINE gives ORA-01756 and the block does not run. Use q'[...]' or double the quote.

Is the data saved when ORA-01756 occurs?

No. The statement is not executed. In the test the table still had 0 rows.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0