Monday, November 28, 2005

In tracking down a bug today, I needed to put "control" characters into an Oracle SQL statement.  Since it was difficult to find using available docs and search engines, I decided to put it here to help out others who may be looking for the same thing.  I do not claim this is the best or easiest way of accomplishing it.  It just works, and that's what I needed.

So, here is how to escape control characters (or presumably any unicode character) within a string in Oracle SQL or PL/SQL:

UNISTR('\0008')

This will give you the backspace (ASCII 08) character.

So, the UNISTR function encodes backslash ("\") followed by four (hex) digits as a single unicode character. (actually it doesn't need to be 4 hex digits.  It will stop at the first non-hex digit. But, it will still "eat" 4 characters from the string.)

(Note: this is for XXXX2 column types like VARCHAR2 that support unicode.  I don't know if/how this works on non-unicode types. Also, this is for Oracle 10g.)

UPDATE: Shortly after writing this, I discovered ASCIISTR, which is identical in syntax to and probably preferable in the case of control characters (as opposed to real unicode characters like accents, symbols, etc.)  ASCIISTR is likely compatible with earlier versions of Oracle as well.

posted on Monday, November 28, 2005 3:10:57 PM (Pacific Standard Time, UTC-08:00)  #    Comments [1]
Related posts:
Random fun book thing and CLR In-Proc SxS
LinqToStdf now on CodePlex
Image Slicer for Deep Zoom in Silverlight 2
Silverlight limitations and Constrained Callvirt in IL
What are the generic Delegates in the framework for?
What is System.__Canon and why is it on my stack?
Tracked by:
"stat quo high beams" (stat quo high beams) [Trackback]
"plastic model helicopters" (plastic model helicopters) [Trackback]
"tallahassee realty" (tallahassee realty) [Trackback]
"thomas richter copywriter" (thomas richter copywriter) [Trackback]
"deca commissary cigarette policy" (deca commissary cigarette policy) [Trackback]
"Golfing in New Mexico" (Golfing in New Mexico) [Trackback]
"talent oregon" (talent oregon) [Trackback]
"diecast collectibles" (diecast collectibles) [Trackback]
"corporate housing annapolis" (corporate housing annapolis) [Trackback]
"custom fabricators lansing michigan" (custom fabricators lansing michigan) [Trackback]
"sokkia robotic total stations" (sokkia robotic total stations) [Trackback]
"porch swing" (porch swing) [Trackback]
"waterproofing area under deck" (waterproofing area under deck) [Trackback]
"kingdom hearts movie" (kingdom hearts movie) [Trackback]
"timesheet tracking" (timesheet tracking) [Trackback]
"Tennis Game Rules" (Tennis Game Rules) [Trackback]
"nudist resorts" (nudist resorts) [Trackback]
"free linux" (free linux) [Trackback]
"how to build a sugar glider cage" (how to build a sugar glider cage) [Trackback]
"chicago basement waterproofing" (chicago basement waterproofing) [Trackback]
"antenna design" (antenna design) [Trackback]
"lhasa apso puppies for sale" (lhasa apso puppies for sale) [Trackback]
"profits from webcasting" (profits from webcasting) [Trackback]
"maya personal learning edition" (maya personal learning edition) [Trackback]
"blind boys of alabama" (blind boys of alabama) [Trackback]
"shemale escorts philadelphia" (shemale escorts philadelphia) [Trackback]
"2005 Dodge Ram 1500 ratings" (2005 Dodge Ram 1500 ratings) [Trackback]
"t%27s lounge" (t%27s lounge) [Trackback]
"ed powers wholesale" (ed powers wholesale) [Trackback]
"missouri rv dealers" (missouri rv dealers) [Trackback]
"Tapestry of Grace" (Tapestry of Grace) [Trackback]
"search engine optimization agency" (search engine optimization agency) [Trackback]
"ass juice" (ass juice) [Trackback]