Oracle PL/SQL - Using Single Quote Characters as Part of Text Strings


The single quote character is used to enclose the whole string.


SQL>--  ww  w.  ja  v  a  2 s .c o  m
SQL> declare
  2        v_text1_tx VARCHAR2(50) :='It''s''s text.'; --2
  3        v_text2_tx VARCHAR2(50) :=q'!It's's text.!'; --3
  4        v_text3_tx VARCHAR2(50) :=q'[It's's text.]'; --4
  5  begin
  7        DBMS_OUTPUT.PUT_LINE(v_text1_tx);
  8        DBMS_OUTPUT.PUT_LINE(v_text2_tx);
  9        DBMS_OUTPUT.PUT_LINE(v_text3_tx);
 10  end;
 11  /
It's's text.
It's's text.
It's's text.

PL/SQL procedure successfully completed.


You can declare the whole string to be enclosed in quotes by using the construct q'!text!'.

Using this approach, you can type the string exactly as you want it to appear.

You can use other delimiters not only !, but <>, [], {}, and () to declare the start and end of a quoted string.

Text literals are case sensitive. This means that 'text' and 'Text' are two different literals.

Related Topic