问题描述
是否可以使用新 Oracle 中的 val notLaunchedFromNotification = FlagHelper.notLaunchedFromNotification(this)
函数之类的功能?
我有 11.2 并且想做这样的事情:
CONTAINS
据我所知,我不能在这里使用 select * from cars
inner join customers on customers.as_id = cars.as_id
where cars.type like 'AUDI' and contains(request,customers.name,1) > 0;
,因为 LIKE
不是固定值。
有没有办法为旧的 Oracle 找到一些解决方法?
解决方法
您可以按如下方式使用 LIKE
:
select *
from cars
inner join customers on customers.as_id = cars.as_id
where cars.type = 'AUDI' -- You can use = here
and request like '%' || customers.name || '%';
注意: contains
子句用于在 Oracle Text 索引中查找特定字符串。它不能应用于普通列。
CONTAINS
是一个 Oracle 文本函数; Oracle 11g 支持 Oracle Text。
只需在列上创建一个 Oracle 文本上下文索引:
CREATE TABLE cars ( as_id,type,request ) AS
SELECT 1,'AUDI','Requested by alice abbots on 2020-01-07' FROM DUAL;
CREATE INDEX cars__request__textidx ON cars(request) INDEXTYPE IS CTXSYS.CONTEXT;
CREATE TABLE customers ( as_id,name ) AS
SELECT 1,'Alice Abbots' FROM DUAL;
然后你的查询:
select * from cars
inner join customers on customers.as_id = cars.as_id
where cars.type like 'AUDI' and contains(request,customers.name,1) > 0;
输出:
AS_ID | TYPE | REQUEST | AS_ID | NAME ----: | :--- | :-------------------------------------- | ----: | :----------- 1 | AUDI | Requested by alice abbots on 2020-01-07 | 1 | Alice Abbots
dbfiddle here