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

Introduction

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

Demo

SQL>
SQL>-- w  ww.j  a  v  a 2 s .  c o m
SQL> declare
  2        v_text1_tx VARCHAR2(50) :='It''s book2s.com''s text.'; --2
  3        v_text2_tx VARCHAR2(50) :=q'!It's book2s.com's text.!'; --3
  4        v_text3_tx VARCHAR2(50) :=q'[It's book2s.com's text.]'; --4
  5  begin
  6
  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 book2s.com's text.
It's book2s.com's text.
It's book2s.com's text.

PL/SQL procedure successfully completed.

SQL>

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