Sybase数据库使用总结
Sybase数据库使用总结
1、对xml类型的字段作为查询条件
XmlValue字段中存储的内容
[html]
<ContentInfo><CFBundleVersion>1.0</CFBundleVersion><CFBundleIdentifier>com.ciat.mobile.HKMobileEGov</CFBundleIdentifier><CFBundleName>Zak</CFBundleName><CFBundleDisplayName>Zak</CFBundleDisplayName></ContentInfo>
查询的存储过程
[sql]
ALTER PROCEDURE "DBA"."xml_select_condition"()
BEGIN www.zzzyk.com
SELECT XmlID,XmlValue FROM Justsy_Xml WHERE (SELECT VER FROM OPENXML(XmlValue,'/ContentInfo/CFBundleVersion') WITH ("VER" LONG VARCHAR '.'))='1.10' ;
END
2、XMLATTRIBUTES为XML元素添加属性,如果不取别名就使用填写的作为属性名
[sql]
SELECT XMLELEMENT(NAME Device,XMLATTRIBUTES(DeviceID AS D,ContactName)) FROM Device WHERE DeviceID > 400
结果显示:
[sql]
<Device D="410" ContactName="OPOAAA"/>
3、XMLCONCAT对两个XML进行连接
[sql]
SELECT XMLCONCAT(XMLELEMENT(NAME DeviceID,DeviceID),XMLELEMENT(NAME ContactName,ContactName)) AS DeviceXML FROM Device ;
结果: www.zzzyk.com
[sql]
<DeviceID>427</DeviceID><ContactName>ww</ContactName>
4、XMLFOREST( element-content-expression [ AS element-name ],... )element-content-expression 一个字符串。对每个所指定的 element-content-expression 参数生成一个元素。element-content-expression 值将成为元素的内容。
[sql]
SELECT DeviceID,XMLELEMENT(NAME Device,XMLFOREST(PhoneNum AS phoneNum,ContactName AS contactName)) FROM Device WHERE DeviceID > 400 ;
结果:
[sql]
<Device><phoneNum>13022362323</phoneNum><contactName>OPOAAA</contactName></Device>
作者 akwolf