1

我有一个查询:

Select * 
from table 
where 
field1 LIKE '%12345%' (12345 being a column value : field2) *Works*

我想在 LIKE 运算符中使用列字段值而不是硬编码。尝试使用连接:

where field1 LIKE concat(concat('%',field2), '%') *doesnt work*

尝试使用 regexp_like:

where regexp_like(field1, Cast(field2 as character)) *doesnt work*
4

2 回答 2

0

只使用一个 concat

where field1 LIKE concat( '%',TRIM(field2), '%') 
于 2016-03-17T07:32:56.520 回答
0

见下文:

dbadmin=> create table test1 (a varchar(100));

CREATE TABLE
dbadmin=> 

insert into test1 values('Good morining ');
 OUTPUT
--------
      1
(1 row)

dbadmin=> select * from test1 where a like '%'||a||'%';
       a
----------------
 Good morining
(1 row)
于 2016-03-17T09:07:27.990 回答