码迷,mamicode.com
首页 > 其他好文 > 详细

sedna进行xquery查询

时间:2015-07-06 18:00:44      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:linux   数据库   xml   sedna   xquery   

有一个文件book.xml:

<books>
	<book>
		<name>The Call Of Wild</name>
		<author>Jack London</author>
		<price>32.5$</price>
		<date>2015-7-6</date>
	</book>
	<book>
		<name>Wuthering Heights</name>
		<author>Emily Bronte</author>
		<price>40$</price>
		<date>2015-7-5</date>
	</book>
</books>


创建books数据库:

[root@localhost xuzhina]#se_cdb books
Creating a database (this can take a few minutes)...
The database 'books' has been created successfully

启动它:

[root@localhost xuzhina]#se_sm books
Starting database recovery or hot-backup restoration...
Database is in consistent state. Starting...
SM has been started in the background mode

创建一个collection叫novel:

[root@localhost xuzhina]#se_term -query "CREATE COLLECTION 'novel'" books
UPDATE is executed successfully

加载进去:

[root@localhost xuzhina]#se_term -query "LOAD 'book.xml' 'book' 'novel'" books
Bulk load succeeded

查询整个文件:

[root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books return $p" book
s
<books>
  <book>
    <name>The Call Of Wild</name>
    <author>Jack London</author>
    <price>32.5$</price>
    <date>2015-7-6</date>
  </book>
  <book>
    <name>Wuthering Heights</name>
    <author>Emily Bronte</author>
    <price>40$</price>
    <date>2015-7-5</date>
  </book>
</books>


查询book:

[root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book return $p"
 books
<book>
  <name>The Call Of Wild</name>
  <author>Jack London</author>
  <price>32.5$</price>
  <date>2015-7-6</date>
</book>
<book>
  <name>Wuthering Heights</name>
  <author>Emily Bronte</author>
  <price>40$</price>
  <date>2015-7-5</date>
</book>

查询某个书名的book:

[root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book[name='The
Call Of Wild'] return $p" books
<book>
  <name>The Call Of Wild</name>
  <author>Jack London</author>
  <price>32.5$</price>
  <date>2015-7-6</date>
</book>

查询第2本书(记住它的索引是从1开始的):

[root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book[2] return
$p" books
<book>
  <name>Wuthering Heights</name>
  <author>Emily Bronte</author>
  <price>40$</price>
  <date>2015-7-5</date>
</book>

查询某个书的书名包括某个词语,比如Call:

[root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book[contains(n
ame, 'Call')] return $p" books
<book>
  <name>The Call Of Wild</name>
  <author>Jack London</author>
  <price>32.5$</price>
  <date>2015-7-6</date>
</book>


版权声明:本文为博主原创文章,未经博主允许不得转载。

sedna进行xquery查询

标签:linux   数据库   xml   sedna   xquery   

原文地址:http://blog.csdn.net/xuzhina/article/details/46775319

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!