【数据库】3数据类型、运算符
来源:互联网 发布:云计算p层 编辑:程序博客网 时间:2024/05/29 02:17
八数据类型
插入系统当前时间日期
insert into 表 values (current_time()),(current_date()),(now());
year:
00~69→2000~2069
70~99→1970~1999
0→0000
2166→0000
time:
1112→00:11:12
11:12→11:12:00
23:23→23:23:00
210:10→2*24+10=58:10:00 DHH→D*24+HH
10→00:00:10
101112→10:11:12
107010→00:00:00超出时间范围
enum
例1
创:create table tmp9(
enm enum(‘first’,’second’,’thrid’));
查:select enm,enm+0 from tmp9;
结:
first 1
second 2
thrid 3
null null
例2
创:
create table tmp10
(soc int,level enum(‘excellent’,’good’,’bad’));
插:
insert into tmp10 values(70,’good’),(90,1),(75,2),(50,3),(100,’best’);
结:
soc, 70 , 90 , 75 , 50 , 100
level,good,excellent,good,bad
set
创:
create table tmp11(
s set(‘a’),(‘b’),(‘c’),(‘d’);
插:insert into tmp11 values(‘a’),(‘a,b,a’),(‘c,a,d’),(‘a,x,b,y’);
结:a,ab,acd,ab
九运算符
1算术运算符
create table tmp14(num int);
insert into tmp14 value(64);
select num,num+10,num*2,num/2,num%3,num/0,num%0 from tmp14;
64,74,128,32.00,1,null,null
2比较运算符
例1:
select 1=0,’2’=2,2=2,’0.02’=0,’b’=’b’,(1+3)=(2+2),null=null;
结:0,1,1,0,1,1,null
<=>结:0,1,1,0,1,1,1
例2:字符串
查:select null<>null,’good’<=’good’,null<=null
结:null,0,null good第3个0>god第3个d
‘a’=’A’返回1 使用binary二进制返回0
例3:isnull
查:select null is null ,is null(null),isnull(10),10 is null;
结:1,1,0,1
例4:
select 4 between 4 and 6,‘x’between ‘f’and‘g’;
结:1,0
例5:
select least(2,0),least(‘a’,’b’,’c’),least(10,null),greatest(10,null);
结:0,a,null,null
例6:
select 2 in(13,5,‘think’),2 not in(1,3,5,‘think’),null in(1,3,‘thinks’),10 in(null,1);
结:0,1,null,null
3like
%匹配任何数目字符,包括0字符
_一个字符
select ‘stud’ like ‘%d’ ,’s’ like null;
1,null
4regexp正则表达式
select ‘ssky’ regexp ‘^s’,from 表 where f_id regexp ‘[ot]’或’[^a-e 1-2]’或’x{2}’;
5逻辑运算符
1)not -!
select not10,not(1-1),!-5,not(!)null,not(!)1+1;
结:0,1,0,null,1
2)and-&&
select 1 and-1,1and0,1 && null,0 && null;
结:1,0,null,0
3)or-||
select 1 or -1 or 0,10 or null,0 || null,null || null
结:1,1,null,null
4)xor a xor b=a and (not b)或(not a) and b
逻辑异或运算符
操作数有null返回null
操作数都非0或为0,返回0
一个为0,一个为非0,返回1
select 1 xor 1,0 xor 0,1 xor 0,1 xor null,1 xor 1 xor 1;
结:0,0,1,null,0
6位运算
①或:|
select 10|15,9|4|2;→15,15
10:1010
15:1111
15:1111=
9:1001
4:0100
2:0010
15:1111=
②异位:^
操作数不同→1
操作数相同→0
select 10^15,1^0,1^1;→5,1,0
10:1010
15:1111
=5:0101
③左移《
select 1《2,4《2;→4,16
1:0000 0001
《:0000 0100=4
《:0001 0000=16
③右移》
select 1》1,16》2;→0,4
④取反~
select 5&~1;→4 ~高于&
1:0001
取反:1110
5:0101
&:0100=4
- 【数据库】3数据类型、运算符
- 数据类型 数据类型转换 运算符
- 数据类型 数据类型转换 运算符
- 数据类型 数据类型转换 运算符
- 作业3(数据类型、变量、运算符)
- Java-----3、数据类型和运算符
- 第3章 数据类型和运算符
- 第三章-数据类型和运算符3
- 数据类型和运算符
- 数据类型、运算符、表达式
- 数据类型和运算符
- 数据类型与运算符
- 数据类型、运算符、表达式
- 数据类型、运算符、表达式
- 数据类型和运算符
- 数据类型、运算符、表达式
- 数据类型和运算符
- 数据类型与运算符
- [绍棠] 如何运行github上react native项目
- C#操作Xml:通过XmlDocument读写Xml文档
- 解决页面有EditText时,软键盘自动弹出
- 机器学习卷积与池化
- Sklearn安装
- 【数据库】3数据类型、运算符
- OK Log设计思路
- github建立仓库、上传、更新
- JAVA WEB工程中的web.xml文件
- Delphi中ActionList及Action使用
- 【Oracle】Oracle中chr()的含义
- require中exports和module.exports
- redux介绍 1
- 我的第一篇