日期:2014-05-16  浏览次数:20334 次

Xquery增删改
XML更新
SQL语句
update customer set info =''where xmlexists
(declare default element namespace ".org";$doc/customerinfo[@Cid=222])

Xquery语句
UPDATE customer set info = xmlquery('transform copy $mycust:=$cust
modify
	do replace $mycust/customerinfo/addr with
		<addr country="Canada">
			<street>25 eastcreek</street>
			<city>a</city>
		</addr>
	return $mycust' passing info AS "cust")WHERE CID = 1005

XML添加
给cid为1005的客户增加一个电话号码,类型为home。
UPDATE customer set info = xmlquery('transform copy $mycust:=$cust
modify
	do insert <phone type="home">
			1111111111
		</phone> after $mycust/customerinfo/phone 
	return $mycust' passing info as "cust")WHERE CID = 1000

XML重命名
将cid为1004的客户电话<phone>重命名为<phonenumber>(需要for,逐条执行)
UPDATE customer set info = xmlquery('transform copy $mycust:=$cust
modify
	for $phone in $mycust/customerinfo/phone return
	do rename $phone as "phonenumber"
	return $mycust' passing info as "cust")WHERE CID = 1004

XML删除
将cid为1000的客户电话<phone>删除(可以整体删除不需要for)
UPDATE customer set info = xmlquery('transform copy $mycust:=$cust
modify
	do delete ($mycust/customerinfo/phone[@type="home"]) 
	return $mycust' passing info as "cust")WHERE CID = 1000


注意:''中的大小写。