PL/SQL use VARRAY in IN CLAUSE

醉酒当歌 提交于 2019-12-04 01:00:05

问题


Is it possible to use VARRAY in IN CLAUSE of pl/sql?


回答1:


Yes, you can, provided that the VARRAY type is a global type (and not local to some PL/SQL code):

CREATE OR REPLACE TYPE str_tab_type IS VARRAY(10) OF VARCHAR2(200);

DECLARE
  l_str_tab str_tab_type;
  l_count NUMBER;
BEGIN
  l_str_tab := str_tab_type();
  l_str_tab.extend(2);
  l_str_tab(1) := 'TABLE';
  l_str_tab(2) := 'INDEX';

  SELECT COUNT(*) INTO l_count
  FROM all_objects
  WHERE object_type IN (SELECT COLUMN_VALUE FROM TABLE(l_str_tab));
END;
/



回答2:


I have the same Problem, but I don't want (and am not allowed) to define a global TYPE

When defining it local,

TYPE fkarraytype  IS VARRAY(10) OF VARCHAR2(10); 
  fkarray fkarraytype;

The compiler Fails with:

Error: PLS-00642: Lokale Erfassungstypen in SQL-Anweisungen nicht zulässig Text: AND fk.strval IN (SELECT COLUMN_VALUE FROM TABLE(fkarray))



来源:https://stackoverflow.com/questions/8476610/pl-sql-use-varray-in-in-clause

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