开发者

Oracle : Alternative of REGEXP_LIKE function in Oracle 8i

I have a SQL that uses REGEXP_LIKE functio开发者_JS百科n in the where clause, now i need the equivalent of that function which will run in Oracle 8i.

The regex look like this:

where REGEXP_LIKE(parm, '^[PMF][[:digit:]]+[_].*')

Thanks in advance.


You could try

WHERE SUBSTR(parm,1,1) IN ('P','M','F')
AND substr(parm,2,1) between '0' and '9'
AND substr(ltrim(substr(parm,2),'0123456789'),1,1) = '_'

First character is P, M or F. Second character is a digit Second character onwards, stripping all the digits from the left, should start with underscore

PS. Please shoot your 8i database. Not only is 8i out of support, 9i and 10g are also out of support (or at least they are in the 'degraded, please stop using them' level of support).


In googling around, it seems there's a package called OWA_PATTERN that was available back as far as 8i. It provided quite a bit of regular expression support. It was apparently part of the PL/SQL Web Toolkit installation. It may or may not be available in your 8i installation. Check with the DBA for the database.

Here is a 9i document that references it.


Unfortunately, prior to REGEXP_LIKE things were rather grim. We had to do this by hand, in the pouring rain, both ways. Something like this is probably necessary:

WHERE SUBSTR(parm,1,1) IN ('P','M','F')
AND digits_followed_by_underscore(SUBSTR(parm,2)) = 'Y'

Using the following procedure (warning: hastily hacked together, not tested):

CREATE PROCEDURE digits_followed_by_underscore(v IN VARCHAR2)
  RETURN VARCHAR2 IS
  digit_found VARCHAR2(1) := 'N';
BEGIN
  IF LENGTH(v) = 0 THEN
    RETURN 'N';
  END IF;
  FOR i IN 1..LENGTH(v) LOOP
    IF SUBSTR(v,i,1) BETWEEN '0' AND '9' THEN
      digit_found := 'Y';
    ELSIF SUBSTR(v,i,1) = '_' THEN
      RETURN digit_found;
    ELSE
      RETURN 'N';
    END IF;
  END LOOP;
  RETURN 'N';
END;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜