XML, JSON 与 Oracle Text 的 Search Index 在 Oracle Database 23c中的增强

在Oracle 23c中,CREATE SEARCH INDEX语句允许我们在XML,JSON,Oracle Text格式上创建搜索索引,统一了他们的语法。

相关文章.

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_DOUBLENUMBERTIMESTAMPVARCHAR2,多个时使用逗号隔开。
  • 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) : 用指定数据类型的范围查询,可用一个或多个数据类型,如NUMBERTIMESTAMPVARCHAR2,多个时使用逗号隔开。
  • TEXT_VALUE(data_types) : 对指定数据类型 全文搜索索引查询 和 范围查询 的组合。
  • TEXT_VALUE_STRING : 全文搜索索引查询 和 NUMBERTIMESTAMP and VARCHAR2 数据类型的范围查询 的组合。

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);

更多相关信息在

Hope this helps. Regards Tim...

 翻译员碎碎念:非标准化数据在数据库中使用越来越多,大家标准不统一,使用上就已经很费劲了,维护上还有各自的语法。这种统一的格式,减轻了学习负担。是个好事。大道至简。

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值