简体   繁体   English

我们可以在存储过程中将LIKE运算符与MEMBER OF运算符一起使用吗?

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

I have an array of data using which I select rows from a table. 我有一个数据数组,可用来从表中选择行。 For that I use member of operator in where clause. 为此,我在where子句中使用operator的成员。 I want to know if we can do that same but by using Like operator along with member of operator. 我想知道是否可以通过使用Like运算符和operator成员来做到这一点。

When my Array consists of{Delhi, Mumbai, Kolkata} I select the rows which have these three values in their row. 当我的数组包含{德里,孟买,加尔各答}时,我选择在其行中具有这三个值的行。 This is how I do that: 这是我的方法:

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

And it works perfectly fine. 而且效果很好。 But If my array has {Del, Mum, Kolk} //parts of the actual names How do I use this array for the same purpose, maybe using Like operator. 但是,如果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;

I expect the output to have all the rows which have cities starting with the alphabet/characters present in the array. 我希望输出中所有行的城市都以数组中的字母/字符开头。 Using member of operator 使用操作员成员

Something like this? 像这样吗

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||'%' )

There is no direct way to use LIKE with MEMBER OF . 没有直接的方法可以将MEMBER OFLIKE一起使用。

If It is the protocol that your collection contains the first three characters of the city name then you can use substr() to match only the first three characters in MEMBER OF . 如果协议是您的集合包含城市名称的前三个字符,则可以使用substr()仅匹配MEMBER OF的前三个字符。

try the following thing: 尝试以下操作:

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 db <> fiddle演示

Cheers!! 干杯!!

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

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