Replace the Oracle function wmsys_wm_concat ()

Source: Internet
Author: User

1.

Create Or Replace FunctionPostgresql (p_tnameVarchar2, P_colnameVarchar2)
ReturnClobIs

V_tmpVarchar2(200);
V_result clob;
V_cum sys_refcursor;
Begin

OpenV_cumFor 'Select' |P_colname| 'From' |P_tname;
Loop
FetchV_cum
IntoV_tmp;
Exit WhenV_cum%Notfound;
V_result:=V_result|V_tmp;
EndLoop;
Dbms_output.put_line (v_result );
ReturnV_result;
End;

Select postgresql ('emp', 'ename') from dual

2. sys_connect_by_path

3. create or replace TYPE zh_concat_im
AUTHID CURRENT_USER AS OBJECT
(
CURR_STR VARCHAR2 (32767 ),
Static function odciaggresponinitialize (sctx in out zh_concat_im) return number,
Member function odciaggregateiterate (self in out zh_concat_im,
P1 IN VARCHAR2) return number,
Member function odciaggresponterminate (self in zh_concat_im,
Returnvalue out VARCHAR2,
Flags in number)
Return number,
Member function odciaggregatemerge (self in out zh_concat_im,
SCTX2 IN zh_concat_im) RETURN NUMBER
);
/

Create or replace type body zh_concat_im
IS
Static function odciaggresponinitialize (sctx in out zh_concat_im)
RETURN NUMBER
IS
BEGIN
SCTX: = zh_concat_im (NULL );
Return odciconst. SUCCESS;
END;
Member function odciaggregateiterate (self in out zh_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 odciaggresponterminate (self in zh_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 zh_concat_im,
SCTX2 IN zh_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;
/

Function:
Create or replace FUNCTION zh_concat (P1 VARCHAR2)
RETURN VARCHAR2 aggregate using zh_concat_im;


Modify the red department to adjust the delimiter between fields

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.