zno2

聚合函数 listagg (超出长度限制时xmlagg)

 

表&数据

CREATE TABLE peoplebuy (people Varchar2(10),buy Varchar2(10),price NUMBER);
INSERT INTO peoplebuy VALUES ('','小猫',10);
INSERT INTO peoplebuy VALUES ('','小狗',200);
INSERT INTO peoplebuy VALUES ('','',20);

原来的结果

SELECT * FROM PEOPLEBUY ORDER BY PEOPLE;

想要的结果

SELECT PEOPLE,
       LISTAGG(BUY, ',') WITHIN GROUP(ORDER BY BUY DESC) AS BUY,
       SUM(PRICE) TOTAL
  FROM PEOPLEBUY
 GROUP BY PEOPLE
 ORDER BY PEOPLE

 

用法

LISTAGG(measure_expr [, 'delimiter'])
  WITHIN GROUP (order_by_clause) [OVER query_partition_clause]

 

当连接的字符串过长时会出现以下错误:

解决方案:

XMLAGG https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions215.htm

XMLType https://docs.oracle.com/cd/B10501_01/appdev.920/a96616/arxml24.htm

RTRIM(XMLAGG(XMLELEMENT(e, t.signature_id, ',').extract('//text()')).getClobVal(),',') very_long_text

聚合元素,提取文本,获取clob,去空格

 

FunctionDescription

XMLType()

Constructor that constructs an instance of the XMLType datatype. The constructor can take in the XML as a CLOB, VARCHAR2 or take in a object type.

createXML()

Static function for creating and returning an XMLType instance.

existsNode()

Takes a XMLType instance and a XPath and returns 1 or 0 indicating if applying the XPath returns a non-empty set of nodes.

extract()

Takes a XMLType instance and an XPath, applies the XPath expression and returns the results as an XMLType.

isFragment()

Checks if the input XMLType instance is a fragment or not. A fragment is a XML instance, which has more than one root element.

getClobVal()

Returns the value of the XMLtype instance as a CLOB

getNumVal()

Returns the value of the XMLtype instance as a NUMBER. This is only valid if the input XMLtpye instance contains a simple text node and is convertible to a number.

getStringVal()

Returns the value of the XMLType instance as a string.

transform()

Takes an XMLtype instance and an associated stylesheet (which is also an XMLtype instance) , applies the stylesheet and returns the result as XML.

toObject()

Converts the XMLType instance to an object type.

isSchemaBased()

Returns 1 or 0 indicating if the input XMLType instance is a schema based one or not.

getSchemaURL()

Returns the XML schema URL if the input is a XMLSchema based.

getRootElement()

Returns the root element of the input instance. Returns NULL if the instance is a fragment

createSchemaBasedXML()

Creates a schema based XMLtype instance from the non-schema based instance using the input schema URL.

createNonSchemaBasedXML()

Creates a non schema based XML from the input schema based instance.

getNamespace()

Returns the namespace for the top level element in a schema based document.

schemaValidate()

Validates the input instance according to the XMLSchema. Raises error if the input instance is non-schema based.

isSchemaValidated()

Checks if the instance has been validated against the schema.

setSchemaValidated()

Sets the schema valid flag to avoid costly schema validation.

isSchemaValid()

Checks if the input instance is schema valid according to the given schema URL.

posted on 2016-08-05 18:02  zno2  阅读(9387)  评论(0编辑  收藏  举报

导航