DB2 – Insert or Update Single Quote April 9, 2010
Posted by ninadgawad in DB2, General, MySQL, Uncategorized.Tags: DB2, INSERT, SINGLE QUOTE, UPDATE
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.



Comments»
No comments yet — be the first.