Is there a way to do a LIKE operation in DB2 against a varchar column in a case insensitive way, without changing the underlying column definition?

Or is there a workaround like SELECT * FROM mytable WHERE mycolumn LIKE '%string%' OR mycolumn LIKE '%STRING%' that would work?

有帮助吗?

解决方案

No. Assuming Db2 for LUW, you can choose a case-insensitive collating table, but only at the database creation time.

You'll have to standardise the case for comparison, with obvious performance implications:

SELECT * FROM mytable WHERE LCASE(mycolumn) LIKE '%string%'

其他提示

Try

SELECT * FROM mytable WHERE REGEXP_LIKE(mycolumn,'string',1,'i')

Will work if your Db2 version supports regular expression functions https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0061494.html and if you escape any regex meta-characters in your string

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top