【问题标题】:Can we use LIKE operator along with MEMBER OF operator in a stored procedure?我们可以在存储过程中使用 LIKE 运算符和 MEMBER OF 运算符吗?
【发布时间】:2019-07-12 06:22:21
【问题描述】:

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

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

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;

我希望输出包含所有具有以数组中的字母/字符开头的城市的行。使用运算符的成员

【问题讨论】:

    标签: sql oracle stored-procedures memberof


    【解决方案1】:

    这样的?

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

    【讨论】:

      【解决方案2】:

      没有直接的方法可以将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

      干杯!!

      【讨论】:

        猜你喜欢
        • 2023-03-15
        • 2018-08-02
        • 2012-03-21
        • 2013-03-31
        • 2011-08-20
        • 2017-10-23
        • 2013-04-29
        • 2015-06-18
        • 1970-01-01
        相关资源
        最近更新 更多