博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL中ISNULL的问题。
阅读量:6970 次
发布时间:2019-06-27

本文共 1148 字,大约阅读时间需要 3 分钟。

今天在写SQL代码的时候写了个 ISNULL(变量1,变量2),返回的结果居然是 "*" ,这个星号,郁闷了很久。

代码大意如下:

declare @str1 varchar(1)declare @str2 intset @str2=222select ISNULL(@str1,@str2)

返回结果:" * ",这个郁闷啊。

修改下代码:

declare @str1 varchar(4)declare @str2 intset @str2=222select ISNULL(@str1,@str2)

返回结果: " 222 " 。

再次修改代码:

declare @str1 varchar(4)declare @str2 varchar(8)set @str2='2222222'select ISNULL(@str1,@str2)

返回结果:"  2222 "。

经过这三次的试验结果:猜测isnull返回的结果类型,与第一个变量是息息相关的,甚至就取决于第一个变量的类型。

 

官方解释:

Syntax

 
ISNULL ( check_expression , replacement_value )

 

Arguments

check_expression

Is the expression to be checked for NULL. check_expression can be of any type.

replacement_value

Is the expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expresssion.

Return Types

Returns the same type as check_expression.

Remarks

The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different.

返回值是第二个参数,会转成第一个参数的类型,转换失败,就会报异常或者出现前面的"*",星号。

 

转载于:https://www.cnblogs.com/huaan011/p/4779320.html

你可能感兴趣的文章
让x86的android模拟器能模拟arm架构系统
查看>>
初学Struts2-自定义拦截器及其配置
查看>>
关于js中的几个小问题。
查看>>
hdoj-2058-the sum problem
查看>>
MySql基础整理
查看>>
Spring Bean Scope 有状态的Bean 无状态的Bean
查看>>
php 批量修改文件格式或重命名
查看>>
Android数据加密之Aes加密
查看>>
InputStream,String相互转化
查看>>
Atitit.gui api自动化调用技术原理与实践
查看>>
详解zabbix安装部署(Server端篇)
查看>>
阿里云负载不支持 WebSocket 协议与 WSS 和 Nginx 配置问题
查看>>
获取Android屏幕尺寸、控件尺寸、状态栏/通知栏高度、导航栏高度
查看>>
Android开之在非UI线程中更新UI
查看>>
redis分布式锁小试
查看>>
007 爬虫(Scrapy库的使用)
查看>>
014——VUE中v-if语法在网站注册中的实际应用
查看>>
docker常用命令
查看>>
vlan与交换机端口模式Access,Hybrid,Trunk
查看>>
Skyline开发3-没有注册类0x80040154
查看>>