0

I want to display the names which is start from 0 to 9. i do not to use reg_exp and like functions.

My data:

select * from emp2;
15326
25371
35371
48615
59718
69718
79718
89718
99718
05326
15326
25371
35371
48615
59718
69718
79718
89718
99718
a19716
b09414
d%5034
!5033
**5031
89718
39718
05326
a19716
b09414
d%5034
!5033
**5031
89718
39718

I used below query to fetch the records.

select * from emp2 where name between '0' and '9';

15326
25371
35371
48615
59718
69718
79718
89718
05326
15326
25371
35371
48615
59718
69718
79718
89718
89718
39718
05326
89718
39718

Result: As i am getting values form 0 to 8.. 9 is not fetching, why?

some more query i tried.

select * from emp2 where name between '+1' and '10';
05326
05326

select * from emp2 where name between '9' and '0';

no rows selected

why this statement is not fetching any of the records

MY expected result: I want to fetch the records whose name starts with 0 to 9.

4

3 回答 3

3

您想要的查询是:

select *
from emp2
where substr(name, 1, 1) between '0' and '9';

between在应用于字符串时会产生误解。表达方式:

name between '+1' and '10'

正在寻找以从 a'+'到 a的字符开头的名称'1'。对于数字,那将是那些以0and开头的数字1

表达方式:

name between '9' and '0'

是向后的,因为 a between 的值需要按顺序排列。

相关表达:

name between '0' and '9'

接近了。9但是当有另一个数字时,它会错过一些东西。

于 2013-08-29T14:18:00.960 回答
2
SELECT * 
FROM   emp2 
WHERE  SUBSTR(name,1,1)  BETWEEN 0 AND 9
于 2013-08-29T14:12:10.057 回答
1
select * from emp2 where name >= '0' and name < ':'

name如果存在,此语句将使用列上的索引。

于 2013-08-29T17:51:38.503 回答