📄 cast.test
字号:
## Test of cast function#select CAST(1-2 AS UNSIGNED);select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);select CAST('10 ' as unsigned integer);select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;select ~5, cast(~5 as signed);explain extended select ~5, cast(~5 as signed);select cast(5 as unsigned) -6.0;select cast(NULL as signed), cast(1/0 as signed);## Bug #28250: Run-Time Check Failure #3 - The variable 'value' is being used # without being def# # The following line causes Run-Time Check Failure on # binaries built with Visual C++ 2005select cast(NULL as unsigned), cast(1/0 as unsigned); select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME);select cast("1:2:3" as TIME);select CONVERT("2004-01-22 21:45:33",DATE);select 10+'10';select 10.0+'10';select 10E+0+'10';# The following cast creates warningsselect CONVERT(DATE "2004-01-22 21:45:33" USING latin1);select CONVERT(DATE "2004-01-22 21:45:33",CHAR);select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));select CAST(0xb3 as signed);select CAST(0x8fffffffffffffff as signed);select CAST(0xffffffffffffffff as unsigned);select CAST(0xfffffffffffffffe as signed);select cast('-10a' as signed integer);select cast('a10' as unsigned integer);select 10+'a';select 10.0+cast('a' as decimal);select 10E+0+'a';# out-of-range casesselect cast('18446744073709551616' as unsigned);select cast('18446744073709551616' as signed);select cast('9223372036854775809' as signed);select cast('-1' as unsigned);select cast('abc' as signed);select cast('1a' as signed);select cast('' as signed);## Character set convertion#set names binary;select cast(_latin1'test' as char character set latin2);select cast(_koi8r'耘釉' as char character set cp1251);create table t1 select cast(_koi8r'耘釉' as char character set cp1251) as t;show create table t1;drop table t1;## CAST to CHAR with/without length#select cast(_latin1'ab' AS char) as c1, cast(_latin1'a ' AS char) as c2, cast(_latin1'abc' AS char(2)) as c3, cast(_latin1'a ' AS char(2)) as c4, hex(cast(_latin1'a' AS char(2))) as c5;select cast(1000 as CHAR(3));create table t1 select cast(_latin1'ab' AS char) as c1, cast(_latin1'a ' AS char) as c2, cast(_latin1'abc' AS char(2)) as c3, cast(_latin1'a ' AS char(2)) as c4, cast(_latin1'a' AS char(2)) as c5;select c1,c2,c3,c4,hex(c5) from t1;show create table t1;drop table t1;## CAST to NCHAR with/without length#select cast(_koi8r'魄' AS nchar) as c1, cast(_koi8r'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -