PostgreSQL之判断字段值被包含话语

PostgreSQL之判断字段值被包含语句

position(substring in string)  return position of substring.

 

表code:

PostgreSQL之判断字段值被包含话语
 

找出code表中code_id字段值被'1-1-2-3-'包含的记录?

 

①, 

select code_id, code_value from code where position(code_id in '1-1-2-3-') > 0 ;

 

②, 

select code_id, code_value from code where '1-1-2-3-' like '%' || code_id || '%' ;

 

结果:

PostgreSQL之判断字段值被包含话语