简体   繁体   English

Oracle:Oracle 8i中REGEXP_LIKE函数的替代方案

[英]Oracle : Alternative of REGEXP_LIKE function in Oracle 8i

I have a SQL that uses REGEXP_LIKE function in the where clause, now i need the equivalent of that function which will run in Oracle 8i. 我有一个在where子句中使用REGEXP_LIKE函数的SQL,现在我需要相当于将在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 第一个字符是P,M或F.第二个字符是数字第二个字符,从左边剥离所有数字,应以下划线开头

PS. PS。 Please shoot your 8i database. 请拍你的8i数据库。 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). 8i不仅没有支持,9i和10g也没有支持(或者至少它们处于'退化,请停止使用它们'的支持水平)。

In googling around, it seems there's a package called OWA_PATTERN that was available back as far as 8i. 在谷歌搜索,似乎有一个名为OWA_PATTERN的包可以回到8i。 It provided quite a bit of regular expression support. 它提供了相当多的正则表达式支持。 It was apparently part of the PL/SQL Web Toolkit installation. 它显然是PL / SQL Web Toolkit安装的一部分。 It may or may not be available in your 8i installation. 它可能在您的8i安装中提供,也可能不提供。 Check with the DBA for the database. 请与DBA一起检查数据库。

Here is a 9i document that references it. 这是一个引用它的9i文档

Unfortunately, prior to REGEXP_LIKE things were rather grim. 不幸的是,在REGEXP_LIKE之前,事情相当严峻。 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM