使用sql检查一个数组中的值是否在另一个数组中

问题描述 投票:1回答:1

如果要在另一个数组中存在一个数组中的某些值,我想根据其执行一些操作。以下是我尝试处理数组的代码的一部分。我有2个数组CL_NM []和CL_NM_FIN []。如果CL_NM []中的值在CL_NM_FIN []中不存在,我想执行更新。请帮助我如何修改我的代码。Here is my code

[尝试执行此操作时,我得到该列已经存在错误,因为在进入else条件之前,for循环不会遍历CL_NM_FIN []中的所有元素。

sql arrays sap hana
1个回答
0
投票

我能够使用以下方法解决此问题:

    DO 
BEGIN
    DECLARE arr1 TINYINT ARRAY = ARRAY(1,2,3,4);
    DECLARE arr2 INTEGER ARRAY = ARRAY(1,2);


--convert array in table rst1 with column name col1
    rst1 = UNNEST(:arr1) as (COL1);
--convert array in table rst2 with column name col1 
    rst2 = UNNEST(:arr2) as (COL1);
--query with minus
    select  col1 from :rst1  
              minus
    select col1 from :rst2;
END;
© www.soinside.com 2019 - 2024. All rights reserved.