Here is my query:
select * from Funds Where fund_id in ('VISTA PREM GOVT', 'DRY SHORT GOV'T', 'VISTA BALANCED', 'FID CONTRA FUND', 'VISTA CAP GRO A', 'DRY NEW LEADER', 'LOAN')
It contains a ' in Dry short gov't', which causes a SQL error. How do I deal with such queries?
It looks like SQL is getting hung up on the single quote mark within your string. Simply insert a second quote mark for every literal quote mark you want in your string. This tells SQL that it is not the end of the string. After doubling your literal quote marks, your SQL should look like this:
SELECT * FROM Funds WHERE fund_id IN ('VISTA PREM GOVT', 'DRY SHORT GOV''T', 'VISTA BALANCED', 'FID CONTRA FUND', 'VISTA CAP GRO A', 'DRY NEW LEADER', 'LOAN')
If your list is being generated dynamically, then you will have to find some way to double your single quotes. This may be accomplished in the host language or by using Oracle's or SQL Server's REPLACE functions.
For More Information
- What do you think about this answer? E-mail the Edtior at email@example.com with your feedback.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical Oracle and SQL questions--or help out your peers by answering them--in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle and SQL
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.