简体   繁体   English

在SQL中如何解决区分大小写的字段

[英]How do I get around case sensitive fields when in SQL

My code is: 我的代码是:

CURSOR get_party_description is      
      select party_name  
      from   ifsapp.IDENTITY_PAY_INFO_ALL
      where  party_type    = :NEW.PARTY_TYPE
      and    identity   = identity_

:NEW_PARTY_TYPE = 'SUPPLIER' while the value in the field is 'Supplier'. :NEW_PARTY_TYPE = 'SUPPLIER'而字段中的值为'Supplier'。 This code will pull back no records but if I change it to 'Supplier', it finds the record 该代码将不回退任何记录,但是如果我将其更改为“ Supplier”,它将找到该记录

How do I change to search with out matching the case? 如何更改搜索条件而不匹配大小写?

You can convert both the variable and the field to upper or lower case. 您可以将变量和字段都转换为大写或小写。

where  UPPER(party_type)    = UPPER(:NEW.PARTY_TYPE)

This might cause a table space scan as the index on the field would be Case sensitive. 这可能导致表空间扫描,因为该字段上的索引区分大小写。

you can get around this by adding a generated column that is upper case and indexing that. 您可以通过添加一个大写的生成列并为其编制索引来解决此问题。

Change both of your values to upper case. 将两个值都更改为大写。 Example: 例:

CURSOR get_party_description is      
      select party_name  
      from   ifsapp.IDENTITY_PAY_INFO_ALL
      where  UPPER(party_type)    = UPPER('SUPPLIER')
      and    identity   = identity_

Besides converting both strings to the same case (upper- or lower-) and then comparing them for equality, most SQL dialects allow one to do a case-insensitive comparison by using the LIKE operator, as follows: 除了将两个字符串都转换为相同的大小写(大写或小写),然后比较它们是否相等之外,大多数SQL方言还允许使用LIKE运算符进行不区分大小写的比较,如下所示:

CURSOR get_party_description is      
    select party_name  
    from   ifsapp.IDENTITY_PAY_INFO_ALL
    where  party_type LIKE :NEW.PARTY_TYPE
    and    identity   = identity_

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

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