MySQL函数(2)

数据加密函数
select password('secret')数据加密,不可逆的 ,区分大小写的
encrypt('secret','bac');unix系统加密程序
select * from users ;
truncate table users ;清空表
inset into  users(username ) values(encode('secret', 'abc'));
select decode(uname,'abc') from users ; abc是钥匙,可以随便改写的 但是加密成都不高
insert into uses(uname ) values(ase_encrypt('secret' , 'bac'))
select aes_decrypt(uname) from users ; 加密成都比较高
select md5('secret');
select sha('secret');

控制流函数
select if(1<10,2,3);
select ifnull(1, 2);如果第一个参数为空, 返回第二个参数,不为空返回第一个参数
select ifnull(null , 2);
select nullif(1,2) ; 1=2返回null 否则返回第一个参数
select case when 1  then 199 when 2 then 200 else  10 end ;

select case '3333'
       when red then 122
       when gree then 233
       else 344
end;


格式化函数,类型转化函数
select date_format(now , '%w , %d  %M  %y %r')
select time_format('100:23:22' , '%h : %i %p')
select inet_aton('192.1.1.1');ip地址转化成IP地址
select inet_ntoa('33434')数字转化成IP地址
select 1+'99'  ; 100
select 1+ cast('99' as sgned);--支持数据类型 binary char , date , time datetime , singed ,

unsinged
select 'f' = binary 'F' , 'f' = cast('F' as  binary)
select convert ('23', singed);类型转化,还可以做字符集转化
select convert('mm' using utf8);

 

你可能感兴趣的:(MySQL函数(2))