一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數據庫技術|

服務器之家 - 數據庫 - PostgreSQL - PostgreSQL中的XML操作函數代碼

PostgreSQL中的XML操作函數代碼

2020-04-21 15:08PostgreSQL教程網 PostgreSQL

PostgreSQL中的XML操作函數代碼,有需要的朋友可以參考一下。

XML內容生成部分
SQL數據生成XML的函數。
1. xmlcomment:生成注釋函數。
xmlcomment(text )
例:

SELECT xmlcomment('hello');
xmlcomment
--------------
<!--hello-->

2. xmlconcat:XML連接函數
xmlconcat(xml [, ...])
例:
SELECT xmlconcat('<abc/>', '<bar>foo</bar>');

xmlconcat
----------------------
<abc/><bar>foo</bar>

連接的XML數據中如果有多個版本聲明的話,連接后的XML只有一個版本聲明。
例:
SELECT xmlconcat('<?xml version="1.1"?><foo/>', '<?xml version="1.1" standalone="no"?><bar/>');

xmlconcat
-----------------------------------
<?xml version="1.1"?><foo/><bar/>

3. xmlelement:生成XML元素函數
xmlelement(name name [, xmlattributes( value [AS attname ] [, ... ])] [ , content, ... ])
例:
SELECT xmlelement(name foo);
xmlelement
------------
<foo/>

SELECT xmlelement(name foo, xmlattributes('xyz' as bar));
xmlelement
------------------
<foo bar="xyz"/>

SELECT xmlelement(name foo, xmlattributes(current_date as bar), 'cont', 'ent');
xmlelement
-------------------------------------
<foo bar="2007-01-26">content</foo>

如果有非法字符的話,非常字符會用 16進制的數字表示出來。
例子:SELECT xmlelement(name "foo$bar", xmlattributes('xyz' as "a&b"));
xmlelement
----------------------------------
<foo_x0024_bar a_x0026_b="xyz"/>

4. xmlforest:生成XML FOREST函數
xmlforest(content [AS name ] [, ...])
例:
SELECT xmlforest('abc' AS foo, 123 AS bar);
xmlforest
------------------------------
<foo>abc</foo><bar>123</bar>

SELECT xmlforest(table_name, column_name)
FROM information_schema.columns
WHERE table_schema = 'pg_catalog';
xmlforest
-------------------------------------------------------------------------------------------
<table_name>pg_authid</table_name><column_name>rolname</column_name>
<table_name>pg_authid</table_name><column_name>rolsuper</column_name>
...
5. xmlpi:生成XML處理命令函數。
xmlpi(name target [, content ])
例:
SELECT xmlpi(name php, 'echo "hello world";');
xmlpi
-----------------------------
<?php echo "hello world";?>

6. xmlroot:修改XML值的根節點屬性函數
xmlroot(xml , version text |no value [, standalone yes|no|no value])
例子:SELECT xmlroot(xmlparse(document '<?xml version="1.1"?><content>abc</content>'),
version '1.0', standalone yes);
xmlroot
----------------------------------------
<?xml version="1.0" standalone="yes"?>
<content>abc</content>

7. xmlagg:xmlagg是集約函數
xmlagg(xml )
例:
CREATE TABLE test (y int, x xml);
INSERT INTO test VALUES (1, '<foo>abc</foo>');
INSERT INTO test VALUES (2, '<bar/>');
SELECT xmlagg(x) FROM test;
xmlagg
----------------------
<foo>abc</foo><bar/>

可以用下面類型的方法改變連接順序。
SELECT xmlagg(x) FROM (SELECT * FROM test ORDER BY y DESC) AS tab;
xmlagg
----------------------
<bar/><foo>abc</foo>

Processing XML
為了處理XML數據,PostgreSL中提供了xpath函數。
xpath(xpath , xml [, nsarray ])

例:
SELECT xpath('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>',
ARRAY[ARRAY['my', 'http://example.com']]);
xpath
--------
{test}
(1 row)

XML和table的映射
以下函數可以導出XML。
table_to_xml(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xml(query text, nulls boolean, tableforest boolean, targetns text)
cursor_to_xml(cursor refcursor, count int, nulls boolean,
tableforest boolean, targetns text)
這些函數的返回值都是XML類型。

還有以下函數。具體內容可以參看用戶手冊。
table_to_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)
cursor_to_xmlschema(cursor refcursor, nulls boolean, tableforest boolean, targetns text)
table_to_xml_and_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xml_and_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)
schema_to_xml(schema name, nulls boolean, tableforest boolean, targetns text)
schema_to_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)
schema_to_xml_and_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)
database_to_xml(nulls boolean, tableforest boolean, targetns text)
database_to_xmlschema(nulls boolean, tableforest boolean, targetns text)
database_to_xml_and_xmlschema(nulls boolean, tableforest boolean, targetns text)

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲免费网站在线观看 | 国产青青草 | 国产一区精品视频 | 青草福利视频 | 91尤物在线播放 | 调教女高中生第3部分 | 青青草原手机在线视频 | 欧美另类z0zxi | 天天干女人 | 91精品导航在线观看 | 国产精品福利在线观看入口 | 海绵宝宝第二季全集免费观看 | 国产免费一区二区三区免费视频 | 国产成人啪精品午夜在线观看 | 日韩手机在线观看 | 色先锋av资源中文字幕 | 69成人网| 国产精品久久久久久久人人看 | 变态人shou交小说 | 亚洲欧美国产另类视频 | 青苹果乐园影院在线播放 | 男人捅女人漫画 | 青青草在线播放 | 亚洲第一男人天堂 | 成人啪精品视频免费网站 | 日本bbwbbw| 特黄级 | 五月天中文在线 | 明星乱淫 | 91麻豆精品国产自产在线 | 农夫成人网 | 免费看国产一级特黄aa大片 | 亚洲欧美综合一区 | 饭冈加奈子黑人解禁在线播放 | tobu8在线观看免费高清 | 日本老妇乱子伦中文视频 | 9总探花新品牛仔背带裤 | 欧美人禽杂交在线视频 | 2020年最新国产精品视频免费 | 女子监狱第二季未删减在线看 | 亚洲一区二区成人 |