加强型WM_CONCAT2函数(不受32767限制的CLOB类型)

CREATE OR REPLACE TYPE WM_CONCAT_IMPL2 AS OBJECT
-- AUTHID CURRENT_USER AS OBJECT
(
CURR_STR nclob, -- 原来为varchar2(32767)
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT WM_CONCAT_IMPL2) RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT WM_CONCAT_IMPL2,
P1 IN nclob) RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN WM_CONCAT_IMPL2,
RETURNVALUE OUT nclob,
FLAGS IN NUMBER)
RETURN NUMBER,
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT WM_CONCAT_IMPL2,
SCTX2 IN WM_CONCAT_IMPL2) RETURN NUMBER
)
;
--定义类型body:
CREATE OR REPLACE TYPE BODY WM_CONCAT_IMPL2
IS
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT WM_CONCAT_IMPL2)
RETURN NUMBER
IS
BEGIN
SCTX := WM_CONCAT_IMPL2(NULL) ;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT WM_CONCAT_IMPL2,
P1 IN nclob)
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 WM_CONCAT_IMPL2,
RETURNVALUE OUT nclob,
FLAGS IN NUMBER)
RETURN NUMBER
IS
BEGIN
RETURNVALUE := CURR_STR ;
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT WM_CONCAT_IMPL2,
SCTX2 IN WM_CONCAT_IMPL2)
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 wm_concat2(P1 nclob)
RETURN nclob AGGREGATE USING WM_CONCAT_IMPL2 ;
/
create or replace procedure a_test(mycol in varchar2,
mytab in varchar2,
mywhere in varchar2,
mysql out varchar2,
my_cursor2 out sys_refcursor) as
my_cursor sys_refcursor;
mysql99 clob;
begin
mysql := 'select (''select ''''''||replace(wm_concat2(to_char(' || mycol ||
')),'','','''''','''''')||'''''' from dual'') from ' || mytab||' where 1=1 '||mywhere;
OPEN my_cursor FOR mysql;
FETCH my_cursor into mysql99;
OPEN my_cursor2 FOR mysql99;
end;
/
[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/345618/viewspace-1060944/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/345618/viewspace-1060944/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值