728x90

인포믹스에서는 listagg나 group_concat 같은 함수가 제공되지 않습니다.

프로시저나 함수같은 프로그램을 사용해야합니다.


아래는 인포믹스 11.5버전에서 실행해본 예제입니다.

AGGREGATE에 대한 자세한 설명은 아래의 페이지를 참고해보세요.


$ dbaccess stores_demo -

> CREATE FUNCTION gc_init...

> CREATE FUNCTION gc_iter...

> CREATE FUNCTION gc_comb...

> CREATE FUNCTION gc_fini...

> CREATE AGGREGATE group_concat...


CREATE FUNCTION gc_init(dummy VARCHAR(255)) RETURNING LVARCHAR;
    RETURN '';
END FUNCTION;
CREATE FUNCTION gc_iter(result LVARCHAR, value VARCHAR(255))
    RETURNING LVARCHAR;
    IF result = '' THEN
        RETURN TRIM(value);
    ELSE
        RETURN result || ',' || TRIM(value);
    END IF;
END FUNCTION;
CREATE FUNCTION gc_comb(partial1 LVARCHAR, partial2 LVARCHAR)
    RETURNING LVARCHAR;
    IF partial1 IS NULL OR partial1 = '' THEN
        RETURN partial2;
    ELIF partial2 IS NULL OR partial2 = '' THEN
        RETURN partial1;
    ELSE
        RETURN partial1 || ',' || partial2;
    END IF;
END FUNCTION;
CREATE FUNCTION gc_fini(final LVARCHAR) RETURNING LVARCHAR;
    RETURN final;
END FUNCTION;
CREATE AGGREGATE group_concat
    WITH (INIT = gc_init, ITER = gc_iter,
          COMBINE = gc_comb, FINAL = gc_fini);

> create table test (name varchar(20),nickname varchar(20));

 
Table created.
 
> insert into test values ('홍길동','구름');
 
1 row(s) inserted.
 
> insert into test values ('심청이','달');
 
1 row(s) inserted.
 
> insert into test values ('변사또','해');
 
1 row(s) inserted.
 
> insert into test values ('홍길동','달');
 
1 row(s) inserted.
 
> insert into test values ('심청이','별');
 
1 row(s) inserted.
 
> insert into test values ('변사또','물');
 
1 row(s) inserted.
 
 
> select name, group_concat(nickname) from test group by name;
 
 
 
name          홍길동
group_concat  구름,달
 
name          변사또
group_concat  해,물
 
name          심청이
group_concat  달,별
 
3 row(s) retrieved.



http://stackoverflow.com/questions/715350/show-a-one-to-many-relationship-as-2-columns-1-unique-row-id-comma-separate

http://www.ibm.com/support/knowledgecenter/en/SSGU8G_11.70.0/com.ibm.sqls.doc/ids_sqs_0358.htm


728x90

+ Recent posts