gpt4 book ai didi

oracle sql varray 包含一个元素

转载 作者:行者123 更新时间:2023-12-02 17:35:30 26 4
gpt4 key购买 nike

我有一个像这样的类型声明:

  FUNCTION ...
IS
TYPE stati_va IS VARRAY (10000) OF varchar(1);
stati stati_va;
v_counter INTEGER := 0;
BEGIN
stati := stati_va ();

--this is actually in a loop so the array contains more values
v_counter := v_counter + 1;
stati.EXTEND;
stati (v_counter) := '4';


--here I would like to determine if the array 'stati' contains a value

到目前为止我已经尝试过以下操作,但这给了我一个错误

      IF '4' member of stati then  <- COMPILE error
IF '4' IN stati then <- COMPILE error

我知道循环遍历数组是可能的,但这有点不方便,因为我需要构建这样的东西:

     IF array contains '4' then
elsif array contains '3' then
elseif array contains '2' then
...

最佳答案

您可以使用条件:

IF 'element' member OF <my_array> THEN

例如,

SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 TYPE v_array
3 IS
4 TABLE OF VARCHAR2(200);
5 my_array v_array;
6 BEGIN
7 my_array := v_array('1','2','3','4');
8 IF '4' member OF my_array THEN
9 dbms_output.put_line('yes');
10 ELSE
11 dbms_output.put_line('no');
12 END IF;
13 END;
14 /
yes

PL/SQL procedure successfully completed.

SQL>

关于oracle sql varray 包含一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391960/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com