17,140
社区成员




SELECT ID,STT,grouping(ID),grouping(STT)
FROM TABLE (CORP('sys1','code1'))
group by grouping sets((ID),(STT));
ORA-00932: 数据类型不一致: 应为 NUMBER, 但却获得 AAA.TYPESTT
CREATE OR REPLACE TYPE "AAA"."TYPESTT"
AS OBJECT( ID VARCHAR2 (30),
STT VARCHAR (10))
CREATE OR REPLACE TYPE "AAA"."CORPSTT" AS TABLE OF TYPESTT
CREATE
OR
REPLACE
FUNCTION "AAA"."CORP"(SYS1 VARCHAR ,
CODE1 VARCHAR)
RETURN CORPSTT PIPELINED AS V1 TYPESTT ;
VCODE VARCHAR(30);
VSYS VARCHAR(10);
V_DATE VARCHAR(10);
BEGIN
VCODE := CODE1 ;
VSYS := SYS1 ;
V_DATE := TO_CHAR(SYSDATE,'YYYY-MM-DD') ;
FOR MYROW IN
(
SELECT
ID ,
STT
FROM
RLCP
UNION ALL
SELECT
CORPID ,
CORPROLE
FROM
RRCP )
LOOP
V1 := TYPESTT(MYROW.ID, MYROW.STT);
PIPE ROW (V1);
END LOOP;
RETURN ;
END ;
with t as (
select 1 id, '服装' ptype, '男装' stype, 78 amount, '2009-06-25' saledate from dual union all
select 2 id, '服装' ptype, '男装' stype, 33 amount, '2009-03-21' saledate from dual union all
select 3 id, '服装' ptype, '男装' stype, 22 amount, '2009-12-17' saledate from dual union all
select 4 id, '服装' ptype, '内衣' stype, 46 amount, '2009-06-25' saledate from dual union all
select 5 id, '服装' ptype, '内衣' stype, 15 amount, '2009-01-26' saledate from dual union all
select 6 id, '服装' ptype, '内衣' stype, 93 amount, '2009-03-13' saledate from dual
)
select id,ptype,stype,sum(amount) samount ,grouping(id) gid,grouping(stype) gs,grouping(ptype) gp from t
group by grouping sets((ptype,stype,id),(ptype,stype),(ptype))
[/quote]
forgetsam,谢谢你的回复,这种方法我试过了,没有问题,但是我的select语句是界面配置来的,语义层暂时不支持在外围定义with t as,需要直接在select语句中构造with t as (
select 1 id, '服装' ptype, '男装' stype, 78 amount, '2009-06-25' saledate from dual union all
select 2 id, '服装' ptype, '男装' stype, 33 amount, '2009-03-21' saledate from dual union all
select 3 id, '服装' ptype, '男装' stype, 22 amount, '2009-12-17' saledate from dual union all
select 4 id, '服装' ptype, '内衣' stype, 46 amount, '2009-06-25' saledate from dual union all
select 5 id, '服装' ptype, '内衣' stype, 15 amount, '2009-01-26' saledate from dual union all
select 6 id, '服装' ptype, '内衣' stype, 93 amount, '2009-03-13' saledate from dual
)
select id,ptype,stype,sum(amount) samount ,grouping(id) gid,grouping(stype) gs,grouping(ptype) gp from t
group by grouping sets((ptype,stype,id),(ptype,stype),(ptype))