I'm looking for the db2 equivalent of T-SQL's:
INSERT INTO People (Surname) VALUES ('O''Hara');
To search for a special character that has a special function in the query syntax, you must escape the special character by adding a backslash before it, for example: To search for the string "where?", escape the question mark as follows: "where\?"
The apostrophe, or single quote, is a special character in SQL that specifies the beginning and end of string data. This means that to use it as part of your literal string data you need to escape the special character. With a single quote this is typically accomplished by doubling your quote.
Use braces to escape a string of characters or symbols. Everything within a set of braces in considered part of the escape sequence. When you use braces to escape a single character, the escaped character becomes a separate token in the query. Use the backslash character to escape a single character or symbol.
There are no "special characters" in SQL databases (including DB2), unless they are special to the application doing the inserting. If you are using parameterized statements: INSERT INTO mytable (mycol) VALUES (?) , anything goes.
Use two apostrophes ''
to get a single apostrophe on DB2 too, according to the DB2 Survival Guide. Isn't that working for you?
Brabster is correct. You are supposed to escape '
with ''
So to insert O'Hara , you will have to write O''Hara
Excerpt from: http://www.michael-thomas.com/tech/db2/db2_survival_guide.htm
Escape character.
To insert a single quote, use 2 single quotes ( '' ). To insert pet's use the following pet''s.
Example: insert into MYTABLE (question,answer) values ('What is your pet''s name?','blacky') `
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With