简体   繁体   中英

Filter centered column SQL Oracle

I try to create a query from an Oracle DB. that is, SELECT FROM and WHERE . the column "ORG" is centered and always has 4 letters. I would like to filter that on one specific Item/ value. I already have WHERE ORG = 'HHAH' or with SBSTRG (ORG ...: somehow nothing works. Does somebody has any idea?

I have values of ' HHAH ' instead of 'HHAH' in the column. There are blanks befor and after the value

You could remove the leading and trailing spaces with the trim() function :

WHERE TRIM(ORG) = 'HHAH'

Using a function on the column value will prevent any index on that column being used (as will like with a leading wildcard); unless you add a function-based index for the trimmed value there isn't much you can do about that.

Do you need the LIKE operator:

WHERE ORG LIKE '%HHAH%'

or

WHERE ORG LIKE '%' || 'HHAH' || '%'

to search for values conatining 'HHAH' ?

I would recommend fixing the data:

update t
    set org = trim(org);

I see no reason to be storing spaces in the name of an org . If you need spaces for reporting purposes, put them there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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