sedna進行xquery查詢,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 booksCreating a database (this can take a few minutes)...The database 'books' has been created successfully
啟動它:
[root@localhost xuzhina]#se_sm booksStarting 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'" booksUPDATE is executed successfully
載入進去:
[root@localhost xuzhina]#se_term -query "LOAD 'book.xml' 'book' 'novel'" booksBulk load succeeded
查詢整個檔案:
[root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books return $p" books<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='TheCall 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(name, '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>
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。