wmsys.wm_concat 超長問題 解決方案

babyyellow發表於2020-12-31


原文:  https://blog.csdn.net/xmm_1030/article/details/46724153


使用wmsys.wm_concat多列合成一列遇到問題
ORA-22813: 運算元值超出系統的限制

10G  總長度不能超過 4k 。 

已經寫了儲存過程作為替代方案了

  1. CREATE OR REPLACE TYPE zh_concat_im
  2. AUTHID CURRENT_USER AS OBJECT
  3. (
  4. CURR_STR clob,
  5. STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT zh_concat_im) RETURN NUMBER,
  6. MEMBER FUNCTION ODCIAGGREGATEITERATE( SELF IN OUT zh_concat_im,
  7. P1 IN VARCHAR2) RETURN NUMBER,
  8. MEMBER FUNCTION ODCIAGGREGATETERMINATE( SELF IN zh_concat_im,
  9. RETURNVALUE OUT clob,
  10. FLAGS IN NUMBER)
  11. RETURN NUMBER,
  12. MEMBER FUNCTION ODCIAGGREGATEMERGE( SELF IN OUT zh_concat_im,
  13. SCTX2 IN zh_concat_im) RETURN NUMBER
  14. );
  15. CREATE OR REPLACE TYPE BODY zh_concat_im
  16. IS
  17. STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT zh_concat_im)
  18. RETURN NUMBER
  19. IS
  20. BEGIN
  21. SCTX := zh_concat_im( NULL) ;
  22. RETURN ODCICONST.SUCCESS;
  23. END;
  24. MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT zh_concat_im,
  25. P1 IN VARCHAR2)
  26. RETURN NUMBER
  27. IS
  28. BEGIN
  29. IF(CURR_STR IS NOT NULL) THEN
  30. CURR_STR := CURR_STR || ',' || P1;
  31. ELSE
  32. CURR_STR := P1;
  33. END IF;
  34. RETURN ODCICONST.SUCCESS;
  35. END;
  36. MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN zh_concat_im,
  37. RETURNVALUE OUT clob,
  38. FLAGS IN NUMBER)
  39. RETURN NUMBER
  40. IS
  41. BEGIN
  42. RETURNVALUE := CURR_STR ;
  43. RETURN ODCICONST.SUCCESS;
  44. END;
  45. MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT zh_concat_im,
  46. SCTX2 IN zh_concat_im)
  47. RETURN NUMBER
  48. IS
  49. BEGIN
  50. IF(SCTX2.CURR_STR IS NOT NULL) THEN
  51. SELF.CURR_STR := SELF.CURR_STR || ',' || SCTX2.CURR_STR ;
  52. END IF;
  53. RETURN ODCICONST.SUCCESS;
  54. END;
  55. END;
  56. create or replace FUNCTION zh_concat(P1 VARCHAR2)
  57. RETURN clob AGGREGATE USING zh_concat_im ;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-2746720/,如需轉載,請註明出處,否則將追究法律責任。

相關文章