ADSM-L

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

2005-06-22 18:23:44
Subject: ?? What character "escapes" wildcards % and _ for SELECTing literal % or _ ??
From: James R Owen <Jim.Owen AT YALE DOT EDU>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Wed, 22 Jun 2005 18:23:35 -0400
[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)

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