sql判断字段是否为空

sql判断字段是否为空,第1张

1、创建测试表,

create table test_null(id varchar2(20),value varchar2(20));

2、插入测试数据;

insert into test_null values(1,'123');

insert into test_null values(2,'abc');

insert into test_null values(3,'');

insert into test_null values(4,'456');

3、查询表中全量数据;select t, rowid from test_null t;

4、编写语句,查询表中value为空的记录;

 select t, rowid from test_null t where value is null;

sql语句查询时,把查询为空的数据显示为零的步骤如下:

我们需要准备的材料分别有:电脑、sql查询器。

1、首先,打开sql查询器,连接上相应的数据库表,例如stu表。

2、点击“查询”按钮,输入:select `name`,IF(score is null, 0, score) from stu。

3、点击“运行”按钮,此时看到score字段为空的数据查出来是0。

在sql中
空值有NULL 和''的形式
当是NULL的时候用 IS NULL判断
当是''的时候用 =''判断
比如
select from table where enddate IS NULL;
select from table where str='';

如果是SELECT如下
SELECT case 字段 when '0' then 'q' else 字段 end 字段 from 表
更新就更简单了
UPDATE 表 SET 字段='Q' WHERE 字段='0'
ORACLE 用decode(字段,'0','q',字段)

sql语句判断字段是否为数字可以参考下面的例子:

select from biao where isnumeric(ziduan)=0 查非数回字答

select from biao where isnumeric(ziduan)=1 查纯数字

扩展资料:

SQL参考语句

查找:select from table1 where field1 like ’%value1%’ (所有包含‘value1’这个模式的字符串)

排序:select from table1 order by field1,field2 [desc]

求和:select sum(field1) as sumvalue from table1

平均:select avg(field1) as avgvalue from table1

参考资料来源:百度百科-结构化查询语言


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/10318178.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-07
下一篇2023-05-07

发表评论

登录后才能评论

评论列表(0条)

    保存