Between clause to Compare two String values [message #587457] |
Sat, 15 June 2013 00:56 |
|
SandeepS
Messages: 15 Registered: April 2013
|
Junior Member |
|
|
Hi All,
I have a problem with Between clause used in where statement to compare two string variable.
Query is like this,
select item_code, item_deacrption
from itm_master, invoce_det
where im_code = item_code
AND invd_item_number BETWEEN (:startNum) AND (:endNum)
Here invd_item_number is a DB field and is of type varchar2(41), and (:startNum),(:endNum) are of same type.
now invd_item_number has one value '001003002001'
if we give :startNum = '001003001002' and :endNum = '001003004006'
:startNum and :endNum is composed of separate field values (ie, 1st 3 character shows color code, next 3 for catagory, next 3 for size etc). These codes are entered separately and are combined at run time.
it is still fetching the invd_item_number with value '001003002001'. (the last set of character(type code) in the :startNum is greater than invd_item_number's type code value. But it is smaller than the previous code (size code), that's why it is fetching).
But how can i get around this as i don't need that value to be fetched.
Please Please help Me.
Thanks
Sandeep
---Every negative event will have with in it a seed of an equal or greater benefit
[Updated on: Sat, 15 June 2013 00:58] Report message to a moderator
|
|
|
Re: Between clause to Compare two String values [message #587463 is a reply to message #587457] |
Sat, 15 June 2013 04:24 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
startNum = 001003001002
001003002001 --> invd_item_number really is between these two
endNum = 001003004006
^
|
this is a number that puts INVD_ITEM_NUMBER between (1-2-4)
Quote:But how can i get around this as i don't need that value to be fetched.
Is it that value only, or are there some other values as well? If it is only that value, add
and invd_item_number <> '001003002001' into conditions. If there are other values as well, either specify them all (using NOT IN operator), or - more likely - your theory is wrong and you'll have to develop a different one.
[Updated on: Sat, 15 June 2013 04:24] Report message to a moderator
|
|
|
|
Re: Between clause to Compare two String values [message #587477 is a reply to message #587469] |
Sat, 15 June 2013 15:03 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Maybe you can use BETWEEN, but using different values. You said that this "001003002001" strings consist of several parts (001 is color code, 003 is category, 002 is size, 001 is something else). So I was thinking that maybe you could use substring instead of the whole string, for examplewhere substr(invd_item_number, 6, 7) between substr(:startNum, 6, 7) AND substr(:endNum, 6, 7) If you find something like that useful (it's just an idea, I don't know what values would satisfy your condition), note that - if there's a lot of data - you might benefit from function based index on that column.
|
|
|
|
|
|
|