jump to navigation

DB2 – Insert or Update Single Quote April 9, 2010

Posted by ninadgawad in DB2, General, MySQL, Uncategorized.
Tags: , , ,
trackback

DB2 Inserting Single Quote
When you try to insert or update a Single Quote in DB2 (‘) in DB2 you will get an error message :
An unexpected token was found following “”. Expected tokens may include: “, WITH WHERE QUERYNO”. SQLSTATE=42601

Solution:
This happens beacuse here ESCAPE sequence ( \) does not work with single quote ( ‘ ).
You can achieve this by prefixing the single quote which you intent to insert by an additional single quote (‘).
i.e: Add two single quotes (”) where ever you have to insert/update one single quote (‘)

Example:
Query with Error:

INSERT INTO TABLENAME VALUES (1, ‘ D’Souza ‘, ‘Active ‘, CURRENT TIMESTAMP);

Use below Query :

INSERT INTO TABLENAME VALUES (1, ‘ D”Souza ‘, ‘Active ‘, CURRENT TIMESTAMP);

The same holds true with update statements.
Do comment if you have nquestions.

Advertisement

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.