在用MySQL编写的查询方面,我确实需要帮助,我想在Oracle /sql中进行转换。我阅读了一些Oracle文档,我认为对于MATCH AGAINST in MySQL,我可以在Oracle中使用CONTAINS,但是在转换列得分、score0和score1时遇到了问题。
SELECT table_id,
MATCH(text) AGAINST('grand hotel') AS score,
MATCH(text) AGAINST('grand') AS score0,
MATCH(text) AGAINST('hotel') AS score1
FROM tbl
WHERE MATCH(text) AGAINST('grand hotel')
ORDER BY score ASC发布于 2013-09-03 05:42:14
我想您在问题中提到的文档是Oracle文本,您已经对这个特性有点熟悉了。您也没有给出为什么涉及PL/SQL的原因,因此下面是一个简单的简单SQL示例,它应该解决您的问题:
数据
create table so32 as
select 1 as id, 'Lorem grand ipsum dolor sit amet, consectetur adipiscing elit. Cras faucibus.' as text from dual union all
select 2 as id, 'Lorem ipsum hotel dolor sit amet, consectetur adipiscing elit. Cras faucibus.' as text from dual union all
select 3 as id, 'Lorem ipsum dolor sit amet, grand consectetur adipiscing elit. Cras faucibus.' as text from dual union all
select 4 as id, 'Lorem ipsum dolor sit amet, consectetur hotel adipiscing elit. Cras faucibus.' as text from dual union all
select 5 as id, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit grand. Cras faucibus.' as text from dual union all
select 6 as id, 'Lorem ipsum dolor sit amet grand hotel, consectetur adipiscing elit. Cras faucibus.' as text from dual
;Oracle文本索引
create index so32_index on so32(text) indextype is ctxsys.context;查询
select id,
score(1) as grand,
score(2) as hotel,
score(3) as grandhotel
from so32
where contains(text, 'grand', 1) > 0
or contains(text, 'hotel', 2) > 0
or contains(text, 'grand hotel', 3) > 0
order by score(3), score(2), score(1)
;结果
ID GRAND HOTEL GRANDHOTEL
---------- ---------- ---------- ----------
1 4 0 0
3 4 0 0
5 4 0 0
4 0 4 0
2 0 4 0
6 4 4 4
6 rows selected.希望这能帮上忙!
https://stackoverflow.com/questions/18581527
复制相似问题