Avoid the hassle of escaping quotes with user-defined quotes



Request Information

Want more information? Fill out the form below and we'll contact you shortly.

Name

Phone

Email

Subject

Message




Date : 7/20/2010

You’re probably quite familiar with the practice of escaping quotes and other special characters in code. But it can sure be a pain if you or your program has to insert lengthy segments of text. Fortunately, Oracle10g eliminated the necessity of escaping quotes in SQL statements by introducing the ability to have user-defined quote characters.

Prior to Oracle10g, if you wanted to include quotes in text, you had to escape the quote with another quote such as:

SELECT 'Pinnacle's p's and q's text' from dual;

With Oracle10g, you can rewrite this as:

SELECT Q'$Pinnacle's p's and q's text$' from dual;

Note that the quoted strings starts with the letter Q, followed by a single quote and the new quote character. It ends with the new quote character and a single quote. We used a dollar sign ($) as our quote character, but you can use other characters if you’d like. Now you can put any quoted text in between your quote characters.

You can use this feature in PL/SQL as well, like this:

CREATE or REPLACE PROCEDURE proc_test (pi_name VARCHAR2) IS
begin
DBMS_OUTPUT.PUT_LINE('Name is: '||pi_name);
end;
/

Then invoke the procedure in an anonymous block such as:,/p>

DECLARE
l_var varchar2(100):= Q'$Pinnacle's p's and q's text$';
BEGIN
proc_test(l_var);
END;
/

The output is:

Name is: Pinnacle's p's and q's text

 


Previous News: 7/13/2010

Avoid over-dependence on SQL*Plus with the Group By and Rollup SQL commands (8i+)

Control the style of links with CSS pseudo-classes

Create hyperlinks that point to areas in a workbook (Excel 2000/2002/2003/2004/2007)

Option Strict places an even tighter grip on applications (VB .NET)

Perform fail-safe firmware upgrades

Print certain slides as handouts (PowerPoint 2000/2002/2003/2004/2007)

Same Day

Avoid misconceptions about SQL injection attacks

Create standalone software packages with the Microsoft Access Runtime

Never hit the wrong database again in the Query window

Remove a sender from your Outlook junk e-mail list (2003/2007)

Split your screen using only the keyboard (Word 2000/2002/2003/2004/2007)

Next News: 7/29/2010

Browse for audio files on FindSounds.com

Create recurring appointments in your Microsoft Outlook calendar (2000/2002/2003/2007)

Keep unnecessary files out of sight, but close at hand (Excel 2000/2002/2003/2004/2007)

Prevent mammoth numerical errors by forcing SQL Server to treat values as decimals

Protect your Web servers with URLScan

Validate radio buttons with a quick JavaScript

Share |
Since 1982, New Horizons Computer Learning Centers has grown to become the largest independent IT training company worldwide. We offer more courses, at more times and in more locations than any other computer and business training company. Businesses and individuals can choose from hundreds of course offerings, delivered by experts, and offered in hundreds of convenient locations around the world.


Albany, NY
(518) 452-6444
10 Airline Drive, Ste 101
Albany, NY 12205
Charlotte, NC
(704) 522-9747
9140 Arrowpoint Blvd, Ste 400
Charlotte, NC 28273
Harrisburg, PA
5095 Ritter Road, Ste 114
Mechanicsburg, PA 17055
Lancaster, PA
(717) 791-0200
1020 New Holland Ave
Lancaster, PA 17601