Thursday, 18 December 2014

Two Single quotes or Alternative Quote Operator

select 'I am a character literal string' from dual;

What about the character literals that contain quotation marks ?

select 'Plural''s have one quote too many' from dual;

Using two single quotes to handle each naturally occurring single quote in a character literal can become messy .
Consider alternative quote(q) operator. The q operator enables you to choose from a set of possible pairs of wrapping symbols for character literals as alternatives to the single quote symbols.
SELECT q'<Plural's can also be specified with alternate quote operators>'  "q<>" FROM DUAL;

SELECT q'[Even square brackets' [] can be used for Plural's]' "q[]" FROM DUAL;

SELECT q'XWhat about UPPER CASE X for Plural's X' "qX" FROM DUAL;

The syntax of alternative quote operator is as follows:
q 'delimiter character literal which may include single quotes delimiter'
where delimiter can be any character or bracket.

No comments:

Post a Comment