tags:

views:

47

answers:

2

Using linq (.net 3.5 +) and predicate builder, I did it like so:

var startsWith3Chars = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z]{3}\-", System.Text.RegularExpressions.RegexOptions.Compiled);
wherePredicate = wherePredicate.And(x => startsWith3Chars.Matches(x.MATERIALUID).Count > 0);

But now I have the need to do this filtering within the command text.

Is there a way to use something like REGEXP_INSTR to limit the results based on a regular expression?

+2  A: 

How about REGEXP_LIKE?

DCookie
APC sort of 1 up-ed you with an example. Thanks for responding.
Merritt
Not a problem - if APC has the time to provide the example, then the credit should go there. If you would have needed the info in a hurry then what I provided would have got you there. It's all about solutions, not scoring.
DCookie
+2  A: 

Given this test data ...

SQL> select name
  2  from t23
  3  /

NAME
----------
SAM-I-AM
MR KNOX
X11
CAT
LORAX

SQL>

... the following query uses REGEXP_LIKE() to return records whose first four characters contain only letters or hyphens:

SQL> select name
  2  from t23
  3  where regexp_like(name, '^[[:alpha:]\-]{4}')
  4  /

NAME
----------
SAM-I-AM
LORAX

SQL>

We can also use REGEXP_INSTR() with the same basic pattern (I have dropped the leading caret):

SQL> select name
  2  from t23
  3  where regexp_instr(name, '[[:alpha:]\-]{4}', 1) = 1
  4  /

NAME
----------
SAM-I-AM
LORAX

SQL>

Oracle added full regular expression support to its SQL in version 10g. Find out more.

APC
Unfortunately working with an older version of Oracle. Thanks though, exactly what I was looking for.
Merritt