0

我真的需要以下用 MySQL 编写的查询的帮助,我想在 Oracle pl/sql 中转换。我阅读了一些 Oracle 文本文档,我想MATCH AGAINST在 MySQL 中我可以CONTAINS在 Oracle 中使用,但是在转换列 score、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
4

1 回答 1

1

我想您在问题中引用的文档是Oracle Text,并且您已经对该功能有些熟悉。您也没有说明为什么应该涉及 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.

希望这可以帮助 !

于 2013-09-03T05:42:14.553 回答