add only unique numbers to IS TABLE OF NUMBER in pl/sql

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 01:08:08

问题


i want to add (product) ids to a "table of numbers" in PL/SQL. Is there a option to check if the table contains a specific number?

i created the table with:

type list_of_produktid_t IS TABLE OF NUMBER INDEX BY binary_integer;

now i iterate over a big table which contains some informations about the product. This informatons, i need to group and order the products. So i can't use the "unique" keyword in the select clause

i need something like:

IF NOT list_of_produktid.contains(l_items(i).item_name) THEN
 list_of_produktid(list_of_produktid.count+1):=l_items(i).item_name;
END IF;

greetings


回答1:


Yes there is - use SQL multiset conditions. See also Comparing Nested Tables with SQL Multiset Conditions from PL/SQL Language Reference.

An example:

declare
  subtype bar_t is pls_integer;
  type bar_list_t is table of bar_t;
  type foo_list_t is table of bar_list_t index by pls_integer;
  v_foos foo_list_t;
  v_find_me constant pls_integer := 3;
begin
  v_foos(1) := bar_list_t(1,3,5,7,9);
  v_foos(2) := bar_list_t(0,2,4,6,8);

  for i in v_foos.first .. v_foos.last loop
    if v_find_me member of v_foos(i) then
      dbms_output.put_line('value ' || v_find_me || ' is found from index ' || i);
    end if;
  end loop;
end;
/

Note that you can negate the logic with not member of.



来源:https://stackoverflow.com/questions/17921486/add-only-unique-numbers-to-is-table-of-number-in-pl-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!