我们可以在存储过程中同时使用 LIKE 运算符和 MEMBER OF 运算符吗?

Can we use LIKE operator along with MEMBER OF operator in a stored procedure?

我有一个数据数组,我使用 table 中的 select 行。为此,我在 where 子句中使用了运算符的成员。我想知道我们是否可以通过使用 Like 运算符和运算符的成员来做同样的事情。

当我的数组包含{Delhi, Mumbai, Kolkata} 我 select 行中包含这三个值的行。 我就是这样做的:

select ...
Into...
From xyz where city member of array;
///Receiving the array from an in parameter of the stored procedure.

而且效果非常好。 但是如果 my array has {Del, Mum, Kolk} //parts of the actual names 我如何将此数组用于相同目的,也许使用 Like 运算符。

Create or replace zz2(ar in array_collection, c out sys_refcursor)
Is
anotherabc tablename.city%type
Begin
Open c
For
Select ABC
Into anotherabc
From tablename where city member of ar;
End zz2;

我希望输出包含数组中存在的城市以 alphabet/characters 开头的所有行。使用运算符

的成员

是这样的吗?

Select ABC
Into anotherabc a
From tablename WHERE EXISTS 
  ( select 1 FROM ( select column_value as city  
     FROM TABLE(ar) ) s where a.city like s.city||'%' )

无法直接将 LIKEMEMBER OF 一起使用。

如果协议规定您的集合包含城市名称的前三个字符,那么您可以使用 substr() 仅匹配 MEMBER OF 中的前三个字符。

尝试以下操作:

DECLARE
  TYPE t_tab IS TABLE OF varchar(3);
  l_tab1 t_tab := t_tab('Del','Mom','Kol');
BEGIN
  DBMS_OUTPUT.put('Is ''Delhi'' MEMBER OF l_tab1? ');
  IF SUBSTR('Delhi',1,3) MEMBER OF l_tab1 THEN -- note the use of SUBSTR here
    DBMS_OUTPUT.put_line('TRUE');
  ELSE
    DBMS_OUTPUT.put_line('FALSE');  
  END IF;
END;
/

db<>fiddle demo

干杯!!