ADSM-L

Re: ?? What character "escapes" wildcards % and _ for SELECTing literal % or _ ??

2005-06-23 08:36:36
Subject: Re: ?? What character "escapes" wildcards % and _ for SELECTing literal % or _ ??
From: "Warren, Matthew (Retail)" <Matthew.Warren AT POWERGEN.CO DOT UK>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Thu, 23 Jun 2005 13:36:07 +0100
Also, the command

Query node "*-*" works....

Computer says 'No'..


-----Original Message-----
From: ADSM: Dist Stor Manager [mailto:ADSM-L AT VM.MARIST DOT EDU] On Behalf Of
TSM_User
Sent: Thursday, June 23, 2005 1:52 AM
To: ADSM-L AT VM.MARIST DOT EDU
Subject: Re: ?? What character "escapes" wildcards % and _ for SELECTing
literal % or _ ??

Looks like when you want to actually search for an _ or % you have to
tell SQL what character you want to use as an escape.  I couldn't find
anything that said what the default escape character is so maybe this is
the only way to do it.

Anyway here is what works
select node_name from nodes where node_name like '%\_%' escape '\'


When you use the word escape followed by quotes and any character in the
quotes that character will be treated like an escape character.  So the
following will work also

select node_name from nodes where node_name like '%!_%' escape '!'

google is my friend  I searched for "escape character for SQL selects"
and the first hit was an example.  I then tested it and it appears to
work.  The page that came up was
<http://www.techonthenet.com/sql/like.htm.  This page had a lot of good
information where it explains

Kyle

James R Owen <Jim.Owen AT YALE DOT EDU> wrote:
[Hey:
If you're really in a hurry, skip to the next page, and see <(@)>,
but you might miss some fun(ny, perhaps even useful?) stuff!]

I just accidentally discovered [!much to my surprise!] that...

The underscore "_" character is the SQL SELECT standard "wildcard"
to match "any single character in the specified position", e.g.,

select node_name from nodes where node_name like '_A_'

[lists all nodes w/ names 3 characters long w/ 'A' in the middle.

[Probably] we all[ready] know [or have discovered] that...

The percent "%" character is the SQL SELECT standard "wildcard"
to match "zero or more characters" [but NOT a NULL string!]

select node_name from nodes where node_name like '%-%'

[lists all nodes w/ hyphenated names, and also bizarre names
like '-', '+-', '1-0', '.-.', '...---...' (morse code!), etc.]

Now, what I really want is a list of nodes w/ names including
a literal underscore "_" character so I first tried...

select node_name from nodes where node_name like '%_%'

[which seems to be exactly equivalent to...]

select node_name from nodes where node_name like '%'

[Both list all existing nodes (because node_name can't be null!)]

Then I borrowed an Oracle DBA's SQL ref.manual and found...

The backslash "/" character is the SQL SELECT standard "escape" used
preceding a wildcard to match that (following) character literally.

<(@)> So, I tried again...

tsm: TST>select node_name from nodes where node_name like '%\_%'

ANR2034E SELECT: No match found using this criteria.
ANS8001I Return code 11.

tsm: TST>select node_name from nodes where node_name like '%_OB'

NODE_NAME
------------------
xxxxxx_OB
yyyyy-OB
zzzzz_OB
aaa_OB
bbbb_OB
ccccOB

tsm: TST> [names partially changed to protect the innocent]

!!!What to do??? [Please, don't say there's no escape!]

ITSM 5.2.3.0 w/ AIX 5.2
--
Jim.Owen AT Yale DOT Edu (203.432.6693)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com



___________________________ Disclaimer Notice __________________________
This message and any attachments are confidential and should only be read by 
those to whom they are addressed. If you are not the intended recipient, please 
contact us, delete the message from your computer and destroy any copies. Any 
distribution or copying without our prior permission is prohibited.

Internet communications are not always secure and therefore Powergen Retail 
Limited does not accept legal responsibility for this message. The recipient is 
responsible for verifying its authenticity before acting on the contents. Any 
views or opinions presented are solely those of the author and do not 
necessarily represent those of Powergen Retail Limited. 

Powergen Retail Ltd is authorised and regulated by the Financial Services 
Authority for the sale and service of general insurance products.

Registered addresses:

Powergen Retail Limited, Westwood Way, Westwood Business Park, Coventry, CV4 
8LG.
Registered in England and Wales No: 3407430

Telephone +44 (0) 2476 42 4000
Fax +44 (0) 2476 42 5432

<Prev in Thread] Current Thread [Next in Thread>