I have the following data:
[sequences]
/a1
/a2
/a3
...
/a10
The query SELECT * FROM sequences WHERE nbr <= '/a10'
should return the list above, instead it returns:
[results]
/a1
/a10
How do I make it return all the rows in the above list?
In String, the == operator is used to comparing the reference of the given strings, depending on if they are referring to the same objects. When you compare two strings using == operator, it will return true if the string variables are pointing toward the same java object. Otherwise, it will return false .
Using String. equals() :In Java, string equals() method compares the two given strings based on the data/content of the string. If all the contents of both the strings are same then it returns true. If any character does not match, then it returns false.
There are three ways to compare String in Java: By Using equals() Method. By Using == Operator. By compareTo() Method.
The less than or equal operator ( <= ) returns true if the left operand is less than or equal to the right operand, and false otherwise.
It works as it should. To compare the numeric value, you'll have to convert these to numbers somehow. A good start would be to use substr(yourfieldname, 3) to cut of the
/a. Then you can use
convert` to typecast it to int, so your final query will look something like:
select * from sequences where convert(int, substr(nbr, 3)) <= 10
Mind that the exact functions and rules for converting strings to ints may very per dbms. This illustrates the general idea, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With