Q
Problem solve Get help with specific problems with your technologies, process and projects.

Checking for single quotes in a variable

I'm trying to insert records in Oracle and values are in a variable. How do I check to see if the variable has a single quote?

I'm trying to insert records in Oracle and values are in a variable. How do I check to see if the variable has a single quote?
The INSTR function will return a non-zero value if the character(s) you are looking for is present in that variable. For instance:

v_quote_location := INSTR(v_my_var,'''');

If v_quote_location is greater than zero, then you know you have a quote. You'd probably like to replace that single quote with two single quotes so that your statement makes some sense. In that case, use the REPLACE function:

v_my_var := REPLACE(v_my_var,'''','''''');

If there are no single quotes, the REPLACE function does nothing. If there are single quotes, they are replaced by two single quotes.

Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close