
正文
oracle怎么差空字段 oracle查询null或空字符
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Oracle中查询某字段不为空或者为空的SQL语句怎么写?
比如\x0d\x0ainsert into table a (a1,b1)values("a1",'');\x0d\x0a对于这种情况,因为表里存的是'',其实是没有内容的,要查询这个字段,不能直接使用\x0d\x0aselect *\x0d\x0afrom a\x0d\x0awhere b1='';\x0d\x0asql中判断非空不能用等号,因为null在sql中被看作特殊符号,必须使用关键字 is和not\x0d\x0a应该如此使用:\x0d\x0aselect * from A where b1 is null\x0d\x0a或者:\x0d\x0aselect * from A where b1 is not null
相关问答
Q1: oracle 怎么判断数据为空
oracle 怎么判断数据为空
需要确定具体是某个字段为空,还是为:' ' 这样的格式。如果是确实为空,那用is null 就可以查出来,如果是后面的就需要用like 字段名 like '% %'
Q2: oracle中如何查询一条记录中都有那个字段是空值
需要用到循环及动态sql。
如test表中有如下数据,其中id和name列有空值。
执行以下内容:
declare
v_count int;--定义变量
v_col varchar2(20);--定义变量
v_sql varchar2(2000);--定义变量
v_last_col varchar2(20);--定义变量
cursor cur_col is select column_name from user_tab_cols where table_name='TEST' order by column_id;--定义游标
begin
select column_name into v_last_col from user_tab_cols where table_name='TEST' and column_id=(select max(column_id) from user_tab_cols where table_name='TEST');--取出表中最后一个字段放入v_last_col
open cur_col;--打开游标
loop --执行循环
fetch cur_col into v_col;--取出游标内容到变量v_col
v_sql:='select count(*) from TEST where '||v_col||' is null';
execute immediate v_sql into v_count;--执行动态sql
if v_count0--如果查询有空值的字段不为空,则输出此字段名
then
dbms_output.put_line(v_col);
end if;
exit when v_col=v_last_col; --退出循环条件
end loop;--结束循环
close cur_col;--关闭游标
end;
执行结果:
oracle怎么差空字段的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于oracle查询null或空字符、oracle怎么差空字段的信息别忘了在本站进行查找喔。







