如何像在oracle中一样使用反向?

How to use reverse like in oracle?

假设这些是 table 中的记录:

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

What is the best query to get below result with 90145 value in where clause:

"Reverse like" 是什么意思?您可以使用 % 字符以您想要的方式进行模式匹配。查看您想要的输出,您需要一个简单的模式,即以 90.

开头的代码值

例如,

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

请参阅此 SQL Fiddle 以获取工作示例。

从你的描述看来你想要

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