2

Consider the following script:

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;

The output of the last two SELECT statements is

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.

What am I doing wrong?

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • 1
    I think that must be a documentation bug. It says 'nested table' in five places, but only mentions 'varray' in that second sentence, *'The return value is TRUE if expr is equal to a member of the specified nested table or varray.'* The same text appears in the 18c documentation so perhaps someone should tell them. – William Robertson Aug 14 '18 at 09:48
  • @WilliamRobertson: Yep, definitely a documentation bug: https://asktom.oracle.com/pls/apex/f?p=100:12:0::NO::P12_ORIG,P12_PREV_PAGE,P12_QUESTION_ID:Y,1,9538544100346396908 – Lukas Eder Aug 22 '18 at 06:48

1 Answers1

0

It is a documentation bug, see this AskTom question and answer.

A workaround is to run this query:

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, in case someone else finds this useful.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509