2017-06-13 133 views
0

我們以XML格式將clob數據存儲在數據庫中,數據類型爲CLOB。dbms_lob.instr花費很長時間才能獲取數據

因此,要獲得這些數據,我們嘗試使用下面的查詢:

select message_xml 
    from table 
where dbms_lob.instr(message_xml, 'A12345678') > 0 
order by message_date; 

但此查詢大約需要一個小時以上很長的時間給我的結果。

有沒有更好的方法來做到這一點。

請注意,我正在解答Oracle 11g數據庫中的查詢。

回答

0

是或否你的問題是一般性的。答案取決於許多因素。 你有兩個簡單的解決方案,一個更復雜。

1)平凡的基於函數的索引。僅適用於一個搜索值。

create fb_trivial index on table(dbms_lob.instr(message_xml, 'A12345678')) 

和查詢利用這個指數

select message_xml 
    from table 
where dbms_lob.instr(message_xml, 'A12345678') > 0 
order by message_date; 

2)提取功能基索引。

create index fb_extract_index on table(extractvalue(xmltype(message_xml),'/path/to/your/value')) 

或版本與namaspaces

create index fb_extract_index on table(extractvalue(xmltype(message_xml),'/ns:path/ns:to/ns:your/ns:value', 'xmlns:ns="namespace:from:xml" ')) 

和查詢利用

select message_xml from table where extractvalue(xmltype(message_xml),'/path/to/your/value')) = 'A12345678' 

3)對於更復雜的解決方案是指oracle-11g-xmlindex-part-1 和Oracle的文檔有關的XML索引本文xmlIndex

+0

整個問題在於我d o在這個數據庫上沒有寫權限。我們只有一個閱讀權限:( –