Wednesday, May 1, 2013

String literal customization ORA-01756: quoted string not properly terminated


String literal customization:

If you get tired of having to put two single
quotes inside of a string literal, you can use q’!…!’, with the string
Placed inside the exclamation points. This lets you use one single quote
in your string rather than requiring two. Here’s a quick example using
an anonymous block:

SET SERVEROUTPUT ON
BEGIN
DBMS_OUTPUT.PUT_LINE('Ron's');
END;
/


This returns the following error:

ORA-01756: quoted string not properly terminated

To fix it, we used to have to use two single quotes in place of the
apostrophe, as in ‘Ron’’s’.


BEGIN
DBMS_OUTPUT.put_line('Ram''a');
END;
/

10gR1 provides another alternative:

BEGIN
DBMS_OUTPUT.put_line(q'!Ram'A!');
END;
 /

This completes successfully and displays Ron’s as intended.




No comments:

Post a Comment