如何在oracle中使用反向?

问题描述 投票:0回答:2

假设这些是表中的记录:

id       code
--------------
1         75
2         90
3         901
4         9014
5         90145
6         80

使用where子句中的90145值获得低于结果的最佳查询是什么:

id       code
--------------
2         90
3         901
4         9014
5         90145
sql oracle sql-like
2个回答
2
投票

根据您的描述,这听起来像你想要的

where '90145' like code ||'%';

快速演示,您的值与排除的稍微相似的额外值:

with t (id, code) as (
  select 1, '75' from dual
  union all select 2, '90' from dual
  union all select 3, '901' from dual
  union all select 4, '9014' from dual
  union all select 5, '90145' from dual
  union all select 6, '80' from dual
  union all select 7, '902' from dual
)
select * from t
where '90145' like code ||'%';

        ID CODE
---------- -----
         2 90   
         3 901  
         4 9014 
         5 90145

0
投票

在where子句中使用90145值获得低于结果的最佳查询是什么:

“反向喜欢”是什么意思?你可以使用%字符按照你想要的方式匹配模式。查看所需的输出,您需要一个简单的模式,即以90开头的代码值。

例如,

select * from table_name
  where "code" like '90%';

有关工作示例,请参阅此SQL Fiddle

© www.soinside.com 2019 - 2024. All rights reserved.