Jeg tror, du ikke kan lave en sådan casting i SQL. Men i PL/SQL kan du:
CREATE OR REPLACE TYPE STRARRAY AS TABLE OF VARCHAR2 (255)
/
DECLARE
tab STRARRAY;
cnt NUMBER:= 0;
BEGIN
SELECT COUNT(*)
INTO cnt
FROM TABLE(CAST(tab AS strarray));
dbms_output.put_line(cnt);
END;
/
Jeg tror, jeg tog fejl i mine antagelser ovenfor. Jeg slettede det ikke, da det stadig er et gyldigt eksempel. Nedenfor eksempel casting af eksisterende tabelkolonne (emp table) med COLLECT som type table_type:
CREATE OR REPLACE TYPE varchar2_ntt AS TABLE OF VARCHAR2(4000);
/
SELECT deptno
, CAST(COLLECT(ename) AS varchar2_ntt) AS emps
FROM scott.emp
GROUP BY deptno
/
-- This is dumb but works:
SELECT deptno
, CAST(COLLECT(ename) AS varchar2_ntt) AS emps
FROM scott.emp
GROUP BY deptno
UNION ALL
SELECT deptno
, CAST(COLLECT(ename) AS varchar2_ntt) AS emps
FROM scott.emp
GROUP BY deptno
/