ORACLE 函数处理的数据返回值过长 character string buffer too small , WMSYS.WM_CONCAT

感谢  :http://blog.csdn.net/mengxiang209/article/details/6927674


--问题

-- ORA-06502: PL/SQL: 数字或值错误 : character string buffer too small
--ORA-06512: 在 "WMSYS.WM_CONCAT_IMPL", line 30

 

--错误   WMSYS.WM_CONCAT()

 SELECT   HEAD.BOOKING_HEAD_ID,
           (SELECT   REPLACE
                     (
                       WMSYS.WM_CONCAT(   CONTAINER.CONTAINER_NO    --这里改用 F_LINK_LOB(.) 处理 

                                   || '/'
                                   || SEAL_NO_1
                                   || '/'
                                   || CONTAINER_TYPE
                                   || '/'
                                   || DECODE (CONTAINER_STATUS_I, 4, 'E', 7, 'L', 'F')),
                        ',',
                        CHR (10)
                     )
              FROM   DOC_BK_CONTAINER CONTAINER
             WHERE   HEAD.BOOKING_HEAD_ID = CONTAINER.BOOKING_HEAD_ID)
              AS CONTAINERS_BOX_INFO
    FROM   DOC_BOOKING_HEAD HEAD
   WHERE   HEAD.BOOKING_HEAD_ID = '2c2881d62e50c1c1012e5573b63e54c2'
ORDER BY   HEAD.BL_NO;

 

  --方法  F_LINK_LOB

CREATE OR REPLACE FUNCTION  F_LINK_LOB (P_STR VARCHAR2)
   RETURN CLOB
 AGGREGATE USING T_LINK_LOB;


--类型T_LINK_LOB

CREATE OR REPLACE TYPE "T_LINK_LOB"
AS
   OBJECT
   (
      V_LOB CLOB,
      STATIC FUNCTION ODCIAGGREGATEINITIALIZE (SCTX IN OUT NOCOPY T_LINK_LOB)
      RETURN NUMBER,
      MEMBER FUNCTION ODCIAGGREGATEITERATE (SELF IN OUT NOCOPY T_LINK_LOB, VALUE IN VARCHAR2)
         RETURN NUMBER,
      MEMBER FUNCTION ODCIAGGREGATETERMINATE
      (
         SELF          IN            T_LINK_LOB,
         RETURNVALUE      OUT NOCOPY CLOB,
         FLAGS         IN            NUMBER
      )
         RETURN NUMBER,
      MEMBER FUNCTION ODCIAGGREGATEMERGE (SELF IN OUT NOCOPY T_LINK_LOB, CTX2 IN T_LINK_LOB)
         RETURN NUMBER
   )

CREATE OR REPLACE TYPE BODY T_LINK_LOB
IS
   STATIC FUNCTION ODCIAGGREGATEINITIALIZE (SCTX IN OUT NOCOPY T_LINK_LOB)
      RETURN NUMBER
   IS
   BEGIN
      SCTX := T_LINK_LOB (NULL);
      DBMS_LOB.CREATETEMPORARY (SCTX.V_LOB, TRUE, DBMS_LOB.SESSION);
      DBMS_LOB.OPEN (SCTX.V_LOB, DBMS_LOB.LOB_READWRITE);
      RETURN ODCICONST.SUCCESS;
   END;

   MEMBER FUNCTION ODCIAGGREGATEITERATE (SELF IN OUT NOCOPY T_LINK_LOB, VALUE IN VARCHAR2)
      RETURN NUMBER
   IS
   BEGIN
      DBMS_LOB.WRITEAPPEND (SELF.V_LOB, LENGTH (VALUE) + 1, VALUE || ',');
      RETURN ODCICONST.SUCCESS;
   END;

   MEMBER FUNCTION ODCIAGGREGATETERMINATE
   (
      SELF          IN            T_LINK_LOB,
      RETURNVALUE      OUT NOCOPY CLOB,
      FLAGS         IN            NUMBER
   )
      RETURN NUMBER
   IS
   BEGIN
      DBMS_LOB.CREATETEMPORARY (RETURNVALUE, TRUE, DBMS_LOB.CALL);
      DBMS_LOB.COPY (RETURNVALUE, SELF.V_LOB, DBMS_LOB.GETLENGTH (SELF.V_LOB) - 1);
      RETURN ODCICONST.SUCCESS;
   END;

   MEMBER FUNCTION ODCIAGGREGATEMERGE (SELF IN OUT NOCOPY T_LINK_LOB, CTX2 IN T_LINK_LOB)
      RETURN NUMBER
   IS
   BEGIN
      NULL;
      RETURN ODCICONST.SUCCESS;
   END;
END;




------------------我参照了上面的,但因为有union  all在我的语句中。有的返回varchar2  ,用了上面的 处理 后,出现了问题。

用了 这个  就好了 :dbms_lob.substr(msg,dbms_lob.getlength(msg),1)    从clob中取出 字符串

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值