Two types of Oracle merge functions

Source: Internet
Author: User

The following articles mainly introduce two types of Oracle merge functions, that is, Introduction to actual application code related to Oracle9i and Oracle10g, and description of the specific use scheme of Oracle9i, the following is an introduction to the specific content of the article. I hope you will have some gains.

9i of Oracle merge functions:

 
 
  1. create type strcat_type as object (  
  2. cat_string varchar2(4000),  
  3. static function ODCIAggregateInitialize(cs_ctx In Out strcat_type) return number,  
  4. member function ODCIAggregateIterate(self In Out strcat_type,value in varchar2) return number,  
  5. member function ODCIAggregateMerge(self In Out strcat_type,ctx2 In Out strcat_type) return number,  
  6. member function ODCIAggregateTerminate(self In Out strcat_type,returnValue Out varchar2,flags in number) return number  
  7. )  
  8. /  
  9. create type body strcat_type is  
  10. static function ODCIAggregateInitialize(cs_ctx IN OUT strcat_type) return number  
  11. is  
  12. begin  
  13. cs_ctx := strcat_type( null );  
  14. return ODCIConst.Success;  
  15. end;  
  16. member function ODCIAggregateIterate(self IN OUT strcat_type,  
  17. value IN varchar2 )  
  18. return number  
  19. is  
  20. begin  
  21. self.cat_string := self.cat_string || ','|| value;  
  22. return ODCIConst.Success;  
  23. end;  
  24. member function ODCIAggregateTerminate(self IN Out strcat_type,  
  25. returnValue OUT varchar2,  
  26. flags IN number)  
  27. return number  
  28. is  
  29. begin  
  30. returnValue := ltrim(rtrim(self.cat_string,','),',');  
  31. return ODCIConst.Success;  
  32. end;  
  33. member function ODCIAggregateMerge(self IN OUT strcat_type,  
  34. ctx2 IN Out strcat_type)  
  35. return number  
  36. is  
  37. begin  
  38. self.cat_string := self.cat_string || ',' || ctx2.cat_string;  
  39. return ODCIConst.Success;  
  40. end;  
  41. end;  
  42. /  
  43. CREATE or replace  
  44. FUNCTION strcat(input varchar2 )  
  45. RETURN varchar2  
  46. PARALLEL_ENABLE AGGREGATE USING strcat_type;  
  47. /  

Usage:

 
 
  1. select t2.kdm_mdid_pk,t2.kdm_title,  
  2. strcat(t3.subject_mc_content) message  
  3. from t_knodoc_rel_subjects t1,  
  4. T_KNO_DOC_METADATA t2,  
  5. T_SUBJECT_MULTILINGUAL_CONTENT t3  
  6. where t1.krs_kdm_mdid_fk=t2.kdm_mdid_pk  
  7. and t1.krs_subid_fk=t3.subject_mc_id_pk  
  8. group by t2.kdm_mdid_pk,t2.kdm_title  

10 Gb of Oracle merge functions:

 
 
  1. select t2.kdm_mdid_pk,t2.kdm_title,WMSYS.WM_CONCAT(t3.subject_mc_content) message  
  2. from t_knodoc_rel_subjects t1,  
  3. T_KNO_DOC_METADATA t2,  
  4. T_SUBJECT_MULTILINGUAL_CONTENT t3  
  5. where t1.krs_kdm_mdid_fk=t2.kdm_mdid_pk  
  6. and t1.krs_subid_fk=t3.subject_mc_id_pk  
  7. group by t2.kdm_mdid_pk,t2.kdm_title   

The above content is an introduction to Oracle merge functions, and I hope you will get some benefits.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.