Home > Database > Mysql Tutorial > sqlserver 数据类型转换小实验

sqlserver 数据类型转换小实验

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:57:52
Original
1241 people have browsed it

sql实验验证数据类型转换实现sql语句

  1. declare @i int
    set @i='a'
    set @i=cast('a' as int)
    set @i=convert(int, 'a')
    print @i --输出结果为:将 varchar 值 'a' 转换为数据类型为 int 的列时发生语法错误。这一点与java不一样

  2. declare @ch varchar(90)
    set @ch=97
    print @ch

    --显示结果为97,说明隐式转换成字符串了

  3. declare @ch varchar(90)
    set @ch=97+'a'
    print @ch

    --输出结果为:将 varchar 值 'a' 转换为数据类型为 int 的列时发生语法错误。为什么不先把数字97转换成字符串,然后再与‘a'连接呢,是不是因为97在前,sqlserver所以尝试这么作呢?换一下位置看看

  4. declare @ch varchar(90)
    set @ch='a'+97
    print @ch

    --输出结果为:将 varchar 值 'a' 转换为数据类型为 int 的列时发生语法错误。不明白sqlserver为什么总是先要把‘a'转换为数字而导致失败。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Problem with tp6 connecting to sqlserver database
From 1970-01-01 08:00:00
0
0
0
Unable to connect to SQL Server in Laravel
From 1970-01-01 08:00:00
0
0
0
Methods of parsing MYD, MYI, and FRM files
From 1970-01-01 08:00:00
0
0
0
SQLSTATE: User login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template