我正在使用摘要逻辑编写报告GROUPING SETS
,但出现此错误:
SELECT c1, c2, c3, SUM(c4) AS MySum
FROM TABLE(get_data()) src
GROUP BY GROUPING SETS ((c1, c2, c3), (c1, c2), c1, c2, ());
-------------------------
ORA-00932: inconsistent datatypes: expected NUMBER got XXX.MYROW
00932. 00000 - "inconsistent datatypes: expected %s got %s"
当我只包含c1
或c2
单独包含时,它工作正常:
GROUP BY GROUPING SETS ((c1, c2, c3), (c1, c2), c1, ());
GROUP BY GROUPING SETS ((c1, c2, c3), (c1, c2), c2, ());
当我直接从t1
表中获取查询时,它也可以正常工作:
SELECT c1, c2, c3, SUM(c4) AS MySum
FROM t1 src
GROUP BY GROUPING SETS ((c1, c2, c3), (c1, c2), c1, c2, ());
我错过了什么?我觉得这很简单。这是我的设置的简化示例:
-- Base table
CREATE TABLE t1 (c1 VARCHAR(10), c2 VARCHAR(10), c3 VARCHAR(10), c4 INTEGER);
-- Row type
CREATE TYPE myrow AS OBJECT (c1 VARCHAR(10), c2 VARCHAR(10), c3 VARCHAR(10), c4 INTEGER);
-- Table type
CREATE OR REPLACE TYPE mytable AS TABLE OF myrow;
-- Get data function
CREATE OR REPLACE FUNCTION get_mydata
RETURN mytable PIPELINED AS
BEGIN
FOR v_rec IN (
SELECT c1, c2, c3, c4
FROM t1
) LOOP
PIPE ROW (myrow(v_Rec.c1, v_Rec.c2, v_Rec.c3, v_Rec.c4));
END LOOP;
RETURN;
END;
数据库版本 - 12.1.0
更新
我的实际功能得到的不同错误(即使有“物化”提示):
ORA-22905: cannot access rows from a non-nested table item 22905.
00000 - "cannot access rows from a non-nested table item"
*Cause: attempt to access rows of an item whose type is not known
at parse time or that is not of a nested table type
*Action: use CAST to cast the item to a nested table type