在 Oracle 中使用 LIKE 和 IN SQL
Using LIKE and IN in Oracle SQL
我需要多次点赞。
我有以下代码
select * from product where product_code LIKE IN ('MS%','TS%')
但是我收到以下错误
ORA-00936: missing expression
00936. 00000 - "missing expression"
我使用的语法正确吗?
谢谢
在 Oracle 中不能同时使用 LIKE
和 IN
。
您必须编写多个 LIKE
并使用 OR
,如下所示:
select * from product
where (product_code LIKE 'MS%'
OR product_code LIKE 'TS%');
您可以使用 OR
:
select *
from product
where product_code like 'MS%' or
product_code like 'TS%';
或者您可以使用正则表达式:
where regexp_like(product_code, '^(MS|TS)')
你也可以使用 union
select * from product where product_code like 'MS%' Union all select * from product where product_code like 'TS%';
我需要多次点赞。
我有以下代码
select * from product where product_code LIKE IN ('MS%','TS%')
但是我收到以下错误
ORA-00936: missing expression 00936. 00000 - "missing expression"
我使用的语法正确吗?
谢谢
在 Oracle 中不能同时使用 LIKE
和 IN
。
您必须编写多个 LIKE
并使用 OR
,如下所示:
select * from product
where (product_code LIKE 'MS%'
OR product_code LIKE 'TS%');
您可以使用 OR
:
select *
from product
where product_code like 'MS%' or
product_code like 'TS%';
或者您可以使用正则表达式:
where regexp_like(product_code, '^(MS|TS)')
你也可以使用 union
select * from product where product_code like 'MS%' Union all select * from product where product_code like 'TS%';