Db2 SQLCODE

SQLCODE -010: String constant not terminated

SQLCODE -010 (SQLSTATE 42603) means a string constant in the SQL starts with an apostrophe but never ends, so Db2 reached the end of the statement still inside the string. The message shows the start of that string.

Other names for this code

Also written as SQLCODE -10, SQL -010, SQLCODE=-10, SQLCODE = -010, db2 -010, sqlstate 42603, SQL0010N, string constant is not terminated.

What it means

A string constant starts at a delimiter and ends at the next matching one. In Db2 for z/OS SQL the delimiter is normally the apostrophe, as in 'SMITH'. Two apostrophes in a row inside a string stand for one apostrophe in the value, so 'O''NEIL' is the name O'NEIL.

If Db2 reaches the end of the statement while it's still inside a string, it can't tell where the string was meant to stop. It returns -010 and puts the first part of the string in the message. Everything after that opening apostrophe was read as text, including any keywords that followed, so the message text often looks like a piece of SQL rather than a value.

For embedded SQL, the precompiler options APOSTSQL and QUOTESQL decide which character delimits strings. With QUOTESQL it's the double quote, and apostrophes are just characters.

Common causes

  • An apostrophe inside a value, such as O'NEIL or a company name, in SQL that a program builds by putting data straight into the statement text. Depending on where the stray apostrophe falls, the same mistake can show up as -104 instead.
  • A closing apostrophe that was simply left out, or deleted during an edit.
  • A string that starts with an apostrophe and ends with a double quote, or the other way round.
  • The statement was cut short. Text past the columns a tool reads is lost, for example columns 73 to 80 of an 80-byte numbered record, which some tools treat as sequence numbers.
  • A long string split across two lines without following the host language's continuation rules.
  • The program was precompiled with QUOTESQL but the SQL uses apostrophes, or the reverse.

How to find the problem

  1. Read the start of the string in the DSNT408I message. Search the statement for those characters to find the opening delimiter.
  2. Count the apostrophes from that point to the end. An odd count means one is missing or one comes from the data.
  3. For dynamic SQL, display the full statement the program built, and look at the data values that went into it.
  4. For SPUFI or batch SQL, check whether the statement runs past column 72, and whether numbering is on in the data set.
  5. For embedded SQL, check the precompile options in the compile JCL for APOSTSQL or QUOTESQL.

How to fix it

  • Double any apostrophe that belongs to the value, as in 'O''NEIL'.
  • Better, stop putting data into SQL text. Use host variables in static SQL, or parameter markers with PREPARE and EXECUTE in dynamic SQL. That removes the problem and closes the door to SQL injection.
  • Add the missing closing apostrophe, and make sure both ends of the string use the same delimiter.
  • Keep SQL within the columns your tool reads, or turn numbering off with NUMBER OFF or UNNUM in ISPF.
  • Match the precompiler option to the delimiter the program uses.

IBM documentation

IBM Db2 for z/OS documentation. Use the documentation for your installed release.

This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.

Report a correction to WND Software.

Questions

How do I put an apostrophe inside a Db2 string?

Write it twice. 'O''NEIL' stores O'NEIL. Using a host variable or parameter marker avoids the issue entirely.

Why does the message show part of my SQL instead of a value?

Once a string is left open, Db2 reads everything after it as text, including keywords. The message shows the start of that runaway string.

Is SQL0010N on Db2 for LUW the same error?

Yes. SQL0010N has SQLSTATE 42603 and means a string constant has no ending delimiter.