表 table
字段 a varchar2(10), b number(10,2)
数据库记录:
a b
a1 0.01
a2 0.02
a3 1.01
a4 1.11
a5 10.01
我想通过sql语句把记录包含"0."的记录给查询出来
下面是我写的sql语句:
select a from table where b like '%0.%';
这样写查询不到数据,where条件修改成"0"或者"."的都可以查询到数据。
想知道为什么“0.”就查询不到数据?是什么特殊字符还是有什么限制?
想查询出正确的结果,应该怎么写?sqloracleselect
字段 a varchar2(10), b number(10,2)
数据库记录:
a b
a1 0.01
a2 0.02
a3 1.01
a4 1.11
a5 10.01
我想通过sql语句把记录包含"0."的记录给查询出来
下面是我写的sql语句:
select a from table where b like '%0.%';
这样写查询不到数据,where条件修改成"0"或者"."的都可以查询到数据。
想知道为什么“0.”就查询不到数据?是什么特殊字符还是有什么限制?
想查询出正确的结果,应该怎么写?sqloracleselect
会先把b转换成字符类型如图,数据类型转换后,小数点前的0会被去掉,所以你就查不到数据了
如你的SQL 只有10.01会返回
这样能达到你的效果,只是感觉比较笨,呵呵!
with tab_char as (
select 'a1'as a,0.01 as b from dual
union
select 'a2',0.02 from dual
union
select 'a3',1.01 from dual
union
select 'a4',1.11 from dual
union
select 'a5',10.01 from dual
)
select * from tab_char t where to_char(t.b,'990.99') like '%0.%';
-1
0.3
10.1
21.1
-0.1用这个SQL能查出来
0.3
10.1
-0.1如果还有好的方法,拿出来一起分享啊!
select a from table where to_char(b,'0.99') like '%0.%';
可以实现我所需要的结果了。
非常感谢大家的帮忙。