在Oracle 23c中,CREATE SEARCH INDEX语句允许我们在XML,JSON,Oracle Text格式上创建搜索索引,统一了他们的语法。
相关文章.
- Indexing JSON Data in Oracle Database 12c Release 1 (12.1.0.2)
- Full Text Indexing using Oracle Text
- All XML Articles
- JSON Support Enhancements in Oracle Database 23c
- JSON Quick Links : Introduction, 12cR1, 12cR2, 18c, 19c, 21c, 23c, All Articles
XML Search Indexes
XDB.XMLIndex类型的索引,在之前的版本引入。允许我们在XML data上创建索引
drop table if exists t1 purge;
create table t1 (
id number,
data xmltype
);
create index t1_xmlindex_idx on t1 (data) indextype is xdb.xmlindex;
在23c中,我们可以对xml格式创建搜索索引,使用格式 CREATE SEARCH INDEX ... FOR XML
完整格式如下
drop table if exists xml_tab purge;
create table xml_tab (
id number,
data xmltype
)
xmltype column data
store as transportable binary xml;
create search index xml_tab_search_idx on xml_tab (data) for XML
parameters (
'search_on text'
);
search_on参数在xml的搜索索引是必选的,以下是他的参考值
- TEXT : 只有文本数据会被全文索引查询。
- VALUE(data_types) : 启用指定数据类型的范围查询,可用一个或多个数据类型,如BINARY_DOUBLE, NUMBER, TIMESTAMP, VARCHAR2,多个时使用逗号隔开。
- TEXT_VALUE(data_types) : 对指定数据类型全文索引查询和范围查询的组合。
XMLTYPE 类型的列必须存储在transportable binary XML中,才能创建搜索索引。对于其他数据类型的XMLTYPE列,我们可以创建Oracle Text的搜索索引来替代
drop table if exists xml_tab purge;
create table xml_tab (
id number,
data xmltype
);
create search index xml_tab_search_idx on xml_tab (data);
JSON Search Indexes
ORACLE 12.1中原始语法格式的JSON搜索索引十分的丑
drop table if exists t1 purge;
create table t1 (
id number,
data clob,
constraint t1_json_chk check (data is json)
);
create index t1_search_idx on t1 (data)
indextype is ctxsys.context
parameters ('section group ctxsys.json_section_group sync (on commit)');
在12.2中,JSON搜索索引的格式简化了。使用CREATE SEARCH INDEX ... FOR JSON。
完整格式如下
drop index if exists t1_search_idx;
create search index t1_search_idx on t1 (data) for json;
参数search_on在XML搜索索引时默认为 TEXT_VALUE
- NONE : JSON 查询不支持。只维护数据指南索引。
- TEXT : 只有text数据被索引用于全文搜索索引。
- VALUE(data_types) : 用指定数据类型的范围查询,可用一个或多个数据类型,如
NUMBER
,TIMESTAMP
,VARCHAR2
,多个时使用逗号隔开。 - TEXT_VALUE(data_types) : 对指定数据类型 全文搜索索引查询 和 范围查询 的组合。
- TEXT_VALUE_STRING : 全文搜索索引查询 和
NUMBER
,TIMESTAMP
andVARCHAR2
数据类型的范围查询 的组合。
Oracle Text Search Indexes
oracle对TEXT数据类型的索引有着悠久的历史。你可以在此读到他
在23C中,我们使用CREATE SEARCH INDEX 创建索引。
完整格式如下
drop table if exists text_tab purge;
create table text_tab (
id number,
data clob
);
create search index text_tab_search_idx on text_tab (data);
更多相关信息在
- CREATE SEARCH INDEX
- Indexing JSON Data in Oracle Database 12c Release 1 (12.1.0.2)
- Full Text Indexing using Oracle Text
- All XML Articles
- JSON Support Enhancements in Oracle Database 23c
- JSON Quick Links : Introduction, 12cR1, 12cR2, 18c, 19c, 21c, 23c, All Articles
Hope this helps. Regards Tim...
翻译员碎碎念:非标准化数据在数据库中使用越来越多,大家标准不统一,使用上就已经很费劲了,维护上还有各自的语法。这种统一的格式,减轻了学习负担。是个好事。大道至简。