mysql中判断字段为null或者不为null 在mysql中,查询某字段为空时,切记不可用 = null, 而是 is null,不为空则是 is not null select nulcolumn from table; if nuncolumn is null then select 1; else select 2; end if; 执行存储过程 调用过程:call sp_add (1,2,@a);select @a;
在sql语句中,如果查找某个文本字段值为空的,可以用select * from 表 where 字段='' ,但是如果这个字段数据类型是text或者ntext,那上面的sql语句就要出错了. 解决办法有很多: 1 . select * from 表 where datalength(字段)=0 2. select * from 表 where cast(字段 as varchar(100))='' 3. select * from 表 where 字段 like ''
比如 insert into table a (a1,b1)values("a1",''); 对于这种情况,因为表里存的是'',其实是没有内容的,要查询这个字段,不能直接使用 select * from a where b1=''; sql中判断非空不能用等号,因为null在sql中被看作特殊符号,必须使用关键字 is和not应该如此使用: select * from A where b1 is null 或者: select * from A where b1 is not null