在 SQL 中对 VARRAY 列使用 Oracle MEMBER OF 运算符

Using Oracle MEMBER OF operator with VARRAY columns in SQL

考虑以下脚本:

CREATE TYPE t1 AS TABLE OF VARCHAR2(10);
/
CREATE TYPE t2 AS VARRAY(10) OF VARCHAR2(10);
/

CREATE TABLE t (
  id NUMBER(10),
  t1 t1,
  t2 t2
)
NESTED TABLE t1 STORE AS t1_nt;

INSERT INTO t VALUES (1, NULL, NULL);
INSERT INTO t VALUES (2, t1('abc'), t2('abc'));

SELECT * FROM t WHERE 'abc' MEMBER OF t1;
SELECT * FROM t WHERE 'abc' MEMBER OF t2;

最后两个SELECT语句的输出是

ID    T1      T2
-------------------
2     [abc]   [abc]

ORA-00932: inconsistent datatypes: expected UDT got 
SQL_XQMZQAMSETXZLGIEEEEBUTFWF.T2

The documentation claims that this operation should be possible for varrays as well as for nested tables:

A member_condition is a membership condition that tests whether an element is a member of a nested table. The return value is TRUE if expr is equal to a member of the specified nested table or varray.

我做错了什么?

这是一个文档错误,请参阅此 AskTom question and answer

解决方法是运行这个查询:

SELECT *
FROM t
WHERE EXISTS (
  SELECT 1 FROM TABLE(t2) WHERE column_value = 'abc'
)

I've written up a blog post showing emulations of all the multiset conditions and operators,以防其他人觉得有用。