Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 如何使用正则表达式将数组中的项与数据库列中的项进行比较?_Oracle_Plsql_Pattern Matching_Bigdata_String Matching - Fatal编程技术网

Oracle 如何使用正则表达式将数组中的项与数据库列中的项进行比较?

Oracle 如何使用正则表达式将数组中的项与数据库列中的项进行比较?,oracle,plsql,pattern-matching,bigdata,string-matching,Oracle,Plsql,Pattern Matching,Bigdata,String Matching,我正在尝试获取数组中的元素列表,如下所示: ['GRADE', 'GRATE', 'GRAPE', /*About 1000 other entries here ...*/ ] 1|'ANTERIOR' 2|'ANTEROGRADE' 3|'INGRATE' 4|'RETROGRADE' 5|'REIGN' ...|... /*About 1,000,000 other entries here*/ for entry in array: for each in column:

我正在尝试获取数组中的元素列表,如下所示:

['GRADE', 'GRATE', 'GRAPE', /*About 1000 other entries here ...*/ ]
1|'ANTERIOR'
2|'ANTEROGRADE'
3|'INGRATE'
4|'RETROGRADE'
5|'REIGN'
...|...
/*About 1,000,000 other entries here*/
for entry in array:
  for each in column:
    if entry.right_match(each):
      print entry
并将它们与Oracle数据库中的一列匹配,该列中包含以下条目:

['GRADE', 'GRATE', 'GRAPE', /*About 1000 other entries here ...*/ ]
1|'ANTERIOR'
2|'ANTEROGRADE'
3|'INGRATE'
4|'RETROGRADE'
5|'REIGN'
...|...
/*About 1,000,000 other entries here*/
for entry in array:
  for each in column:
    if entry.right_match(each):
      print entry
对于G单词数组中的每个条目,我希望遍历Oracle数据库的word列,并尝试查找数组中每个条目的右侧匹配项。在本例中,数据库中的条目2、3和4都将匹配

在任何其他编程语言中,它看起来都是这样的:

['GRADE', 'GRATE', 'GRAPE', /*About 1000 other entries here ...*/ ]
1|'ANTERIOR'
2|'ANTEROGRADE'
3|'INGRATE'
4|'RETROGRADE'
5|'REIGN'
...|...
/*About 1,000,000 other entries here*/
for entry in array:
  for each in column:
    if entry.right_match(each):
      print entry

如何在PL/SQL中执行此操作?

在PL/SQL中,可以通过以下方式执行:

declare
   SUBTYPE my_varchar2_t IS varchar2( 100 );
   TYPE Roster IS TABLE OF my_varchar2_t;  
   names Roster := Roster( 'GRADE', 'GRATE', 'GRAPE');
begin
  FOR c IN ( SELECT id, name FROM my_table )
  LOOP
      FOR i IN names.FIRST .. names.LAST LOOP 
         IF regexp_like( c.name,   names( i )  ) THEN
              DBMS_OUTPUT.PUT_LINE( c.id || '  ' || c.name );
         END IF;
      END LOOP;
  END LOOP;
end;
/
但这是逐行处理,对于大型表来说,速度会非常慢。

我认为最好采用如下方式:

create table test123 as
select 1 id ,'ANTERIOR' name from dual union all
select 2,'ANTEROGRADE' from dual union all
select 3,'INGRATE' from dual union all
select 4,'RETROGRADE' from dual union all
select 5,'REIGN' from dual ;

create type my_table_typ is table of varchar2( 100 );
/

select *
from table( my_table_typ( 'GRADE', 'GRATE', 'GRAPE' )) x
join test123 y on regexp_like( y.name, x.column_value ) 
;

COLUMN_VALUE  ID         NAME      
------------- ---------- -----------
GRADE                  2 ANTEROGRADE 
GRATE                  3 INGRATE     
GRADE                  4 RETROGRADE

D--n!你赢了我!我唯一要添加的是一些regexp语法,例如,regexp_LIKE(y.name,x.column_value | | |'$')只在末尾匹配。使用名称LIKE“%”| | value而不是regexp| LIKE,因为它稍微快一点。此外,还可以使用基于函数的索引来加速搜索,如前所述