自定义函数替换wm_concat函数,在oracle会出现什么不可控因素吗 10
createorreplaceTYPEBODYen_concat_imISSTATICFUNCTIONODCIAGGREGATEINITIALIZE(SCTXINOUTe...
create or replace TYPE BODY en_concat_im IS
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT en_concat_im)
RETURN NUMBER IS
BEGIN
SCTX := en_concat_im(NULL);
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT en_concat_im,
P1 IN VARCHAR2) RETURN NUMBER IS
BEGIN
IF (CURR_STR IS NOT NULL) THEN
CURR_STR := CURR_STR || ';' || P1;
ELSE
CURR_STR := P1;
END IF;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN en_concat_im,
RETURNVALUE OUT VARCHAR2,
FLAGS IN NUMBER)
RETURN NUMBER IS
BEGIN
RETURNVALUE := CURR_STR;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT en_concat_im,
SCTX2 IN en_concat_im) RETURN NUMBER IS
BEGIN
IF (SCTX2.CURR_STR IS NOT NULL) THEN
SELF.CURR_STR := SELF.CURR_STR || ';' || SCTX2.CURR_STR;
END IF;
RETURN ODCICONST.SUCCESS;
END;
END;
create or replace FUNCTION en_concat(P1 VARCHAR2) RETURN VARCHAR2 AGGREGATE USING en_concat_im ;
create or replace TYPE en_concat_im AUTHID CURRENT_USER AS OBJECT
(
CURR_STR VARCHAR2(32767),
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT en_concat_im)
RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT en_concat_im,
P1 IN VARCHAR2) RETURN NUMBER, 展开
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT en_concat_im)
RETURN NUMBER IS
BEGIN
SCTX := en_concat_im(NULL);
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT en_concat_im,
P1 IN VARCHAR2) RETURN NUMBER IS
BEGIN
IF (CURR_STR IS NOT NULL) THEN
CURR_STR := CURR_STR || ';' || P1;
ELSE
CURR_STR := P1;
END IF;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN en_concat_im,
RETURNVALUE OUT VARCHAR2,
FLAGS IN NUMBER)
RETURN NUMBER IS
BEGIN
RETURNVALUE := CURR_STR;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT en_concat_im,
SCTX2 IN en_concat_im) RETURN NUMBER IS
BEGIN
IF (SCTX2.CURR_STR IS NOT NULL) THEN
SELF.CURR_STR := SELF.CURR_STR || ';' || SCTX2.CURR_STR;
END IF;
RETURN ODCICONST.SUCCESS;
END;
END;
create or replace FUNCTION en_concat(P1 VARCHAR2) RETURN VARCHAR2 AGGREGATE USING en_concat_im ;
create or replace TYPE en_concat_im AUTHID CURRENT_USER AS OBJECT
(
CURR_STR VARCHAR2(32767),
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT en_concat_im)
RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT en_concat_im,
P1 IN VARCHAR2) RETURN NUMBER, 展开
展开全部
insert into test values('aaa','1');
insert into test values('bbb','2');
insert into test values('ccc','5');
insert into test values('ddd','3');
select wm_concat(a),wm_concat(b) from test;
WM_CONCAT(A) WM_CONCAT(B)
1 aaa,bbb,ccc,ddd 1,2,5,3
没有问题的。
drop table test;
create table test(a varchar2(30),b varchar2(30),c varchar2(30));
insert into test values('aaa','1','a');
insert into test values('bbb','2','a');
insert into test values('ccc','5','a');
insert into test values('ddd','3','a');
insert into test values('aaaaa','11','b');
insert into test values('bbbbb','22','b');
insert into test values('ccccc','55','b');
insert into test values('ddddd','33','b');
select c,max(a),max(b) from (
select c,wm_concat(a) over (partition by c order by a) a,
wm_concat(b) over (partition by c order by a) b from test
) tt
group by c ;
C MAX(A) MAX(B)
a aaa,bbb,ccc,ddd 1,2,5,3
b aaaaa,bbbbb,ccccc,ddddd 11,22,55,33
insert into test values('bbb','2');
insert into test values('ccc','5');
insert into test values('ddd','3');
select wm_concat(a),wm_concat(b) from test;
WM_CONCAT(A) WM_CONCAT(B)
1 aaa,bbb,ccc,ddd 1,2,5,3
没有问题的。
drop table test;
create table test(a varchar2(30),b varchar2(30),c varchar2(30));
insert into test values('aaa','1','a');
insert into test values('bbb','2','a');
insert into test values('ccc','5','a');
insert into test values('ddd','3','a');
insert into test values('aaaaa','11','b');
insert into test values('bbbbb','22','b');
insert into test values('ccccc','55','b');
insert into test values('ddddd','33','b');
select c,max(a),max(b) from (
select c,wm_concat(a) over (partition by c order by a) a,
wm_concat(b) over (partition by c order by a) b from test
) tt
group by c ;
C MAX(A) MAX(B)
a aaa,bbb,ccc,ddd 1,2,5,3
b aaaaa,bbbbb,ccccc,ddddd 11,22,55,33
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询