In the various SQL products I use, a question mark (?) marks an input parameter in a query.
How do I escape that behavior and search for text that contains a question mark, for example...
SELECT *
FROM A_TABLE
WHERE A_FIELD = 'This is a question mark not an input parameter?'
...where the question mark above is a literal question mark, not a place holder. If the answer is product specific, I am currently using Derby (aka Java DB).
In ANSI SQL, the backslash character (\) is the escape character.
In these statements, you can use a question-mark ( ? ) placeholder where a parameter must be supplied when the statement is executed.
The question mark can appear where a host variable might appear if the statement string were a static SQL statement. If you want to run the same SELECT statement several times, using different values for LASTNAME, you can use an SQL statement that looks like this: SELECT WORKDEPT, PHONENO FROM CORPDATA.
You don't need to escape ?
at all. It has no special meanings with the WHERE
clause as in the case you posted.
As mentioned previously, a '?' following an equals will not act as a wildcard. To search for any rows within a field that contain a question mark, use:
SELECT * FROM A_TABLE
WHERE A_FIELD LIKE '%[?]%'
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