表table_a 里面有个字段 filed_a number类型 可为0,null及其他值。
写了一个sql
select case when filed_a is null then 1 when filed_a=0 then 1 else 1/filed_a end from table_a
但是这个会报除数为0错。
我想请教下各位老师,为什么,不是做了判断么,还会报除数为0呢。
该如何解决这个问题呢。
非常感谢。。
...全文
2996打赏收藏
表字段的非空非0判断无效
表table_a 里面有个字段 filed_a number类型 可为0,null及其他值。 写了一个sql select case when filed_a is null then 1 when filed_a=0 then 1 else 1/filed_a end from table_a 但是这个会报除数为0错。 我想请教下各位老师,为什么,不是做了判断么,还会报除数为0呢。 该如何解决这个问题呢。 非常感谢。。
select case when filed_a is null then 1 when filed_a=0 end from table_a where filed_a is null or filed_a=0
union all
select 1/filed_a from table_a where nvl(filed_a,0)<>0
把那条数据抓出来看看
DECLARE
v_num NUMBER;
BEGIN
FOR x IN(SELECT t.*,t.rowid rid FROM table_a t)LOOP
BEGIN
SELECT CASE WHEN filed_a IS NULL THEN 1 WHEN filed_a=0 THEN 1 ELSE 1/filed_a END INTO v_num FROM table_a WHERE ROWID=x.rid;
EXCEPTION
WHEN ZERO_DIVIDE THEN
dbms_output.put_line('就是它了: '||x.filed_a||'; rowid '||ROWIDTOCHAR(x.rid));
WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
END LOOP;
END;