zoukankan      html  css  js  c++  java
  • SAPHANA学习(24):SQL Function(X)

    153. XMLEXTRACT

    XMLEXTRACT(<XML_document>, <XPath_query> [,<NamespaceDeclarations>])

    <XML_document>

    Specifies an XML document of type CLOB, NCLOB, VARCHAR, or NVARCHAR.

    <XPath_query>

    Specifies an XPath expression of type VARCHAR or NVARCHAR.

    <NamespaceDeclarations>

    Specifies a namespace declaration of type VARCHAR or NVARCHAR.

    XMLEXTRACTVALUE(<XML_document>, <XPath_query> [,<NamespaceDeclarations>])

    XMLTABLE( [ <XML_namespace_clause>, ]

      <row_pattern> PASSING <XML_argument> COLUMNS <column_definitions>

      <error_option>

     )

    创建关系表根据XML字符串

    XMLNAMESPACE (<XML_namespace>[, ...]

      [DEFAULT <default_namespace>]

    <XML_namespace> ::= <namespace_url> AS <namespace_alias>

    <row_pattern> ::= <str_const>

    Describes the format of the xmlNodes in the XML with an XPath expression.

    <XML_argument> ::= <str_const>| <column_ref>

    <column_definitions> ::= <column_name> <column_type> [, <column_name> <column_type>,...]

    <column_name> ::= <identifier>

    <column_type> ::= FOR ORDINALITY

      | <regular_column_return_type> PATH <column_pattern> [DEFAULT <str_const>]

      | <formatted_column_return_type> FORMAT XML PATH <column_pattern> [DEFAULT <str_const>]

    <column_pattern> ::= <str_const>

    Specifies the xPath Expression to use to extract the value for a column.

    <formatted_column_return_type> ::= VARCHAR (<int_const>)| NVARCHAR (<int_const>)

    */

    --不存在?
    
    SELECT XMLEXTRACT(
        '<doc><item><id>1</id><name>Box</name></item><item><id>2</id><name>Jar</name></item></doc>',  
        '/doc/item[2]/name'
     ) FROM DUMMY;
    
    SELECT XMLEXTRACT(                        
        '<doc xmlns:ns1="http://namespace1.sap.com" xmlns:ns2="http:// namespace2.sap.com">
        <ns1:item><ns1:id>1</ns1:id><ns1:name>Box</ns1:name></ns1:item>     
        <ns1:item><ns1:id>2</ns1:id><ns1:name>Jar</ns1:name></ns1:item>     
        <ns2:item><ns2:id>3</ns2:id><ns2:name>Table</ns2:name></ns2:item></doc>',  
        '/doc/ns1:item[2]/ns1:name',  
        'xmlns:ns1="http://namespace1.sap.com" xmlns:ns2="http://namespace2.sap.com"'
     ) FROM DUMMY;
    
    --出错!
    SELECT * FROM
     XMLTABLE('/doc/item'
     PASSING '<doc><item><id>10</id><name>Box</name></item><item><id>20</id><name>Jar</name></item></doc>'
     COLUMNS ID INT PATH 'id',
     NAME VARCHAR(20) PATH 'name' ) AS XTABLE;
  • 相关阅读:
    使用阿里云ECS安装HDFS的小问题
    退役回忆录嘤嘤嘤
    2018 ICPC北京 H ac自动机
    Educational Codeforces Round 54 (Rated for Div. 2) DE
    sa learning
    网络流learning
    Python模块logging
    Python模块unittest
    Linux /dev/shm
    Shell 字符串操作
  • 原文地址:https://www.cnblogs.com/tangToms/p/13939798.html
Copyright © 2011-2022 走看看