简体   繁体   English

在PHP(Oracle数据库)中使用OCI强制不区分大小写

[英]Force case insensitive with OCI in PHP (oracle database)

Well, the title explains it well... 好吧,标题很好地说明了...

I'm using OCI to explore a Oracle database in PHP. 我正在使用OCI探索PHP中的Oracle数据库。

The trouble is that the database is case sensitive, so... when I execute a sentence like 问题在于数据库区分大小写,所以...当我执行类似

SELECT COUNT(username) count, username FROM transactions WHERE username IS NOT NULL GROUP BY username

returns an array like this 返回这样的数组

COUNT USERNAME
213   EMG_COTORA
31    EMG_cotora
123   emg_cotora

This because the database is case sensitive, so... How do I force case insensitive without modifying the database? 这是因为数据库区分大小写,所以...如何在不修改数据库的情况下强制不区分大小写? (I haven't write permission) (我没有写许可)

I assume that in your actual query you have a GROUP BY clause. 我假设在您的实际查询中有一个GROUP BY子句。 You would just need to group by the UPPER(username) 您只需UPPER(username)分组

SELECT upper(username), count(*) cnt
  FROM transactions
 WHERE username IS NOT NULL
 GROUP BY upper(username)

You could also, of course, SELECT and GROUP BY lower(username) or initcap(username) or any other function that converts the different username values into a single value. 当然,您也可以使用SELECTGROUP BY lower(username)initcap(username)或任何其他将不同用户名值转换为单个值的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM