首页 > 数据库技术 > 详细

SQL的基础函数

时间:2021-08-15 11:45:25      阅读:17      评论:0      收藏:0      [点我收藏+]

SQL的基础函数

lower

select lower(name) from students #将students表的所有name字段的数据全都转为小写打印出来

upper

select upper(name) from students #将students表的所有name字段的数据全都转为大写打印出来

length

select length(name) from students #将students表的所有name字段的数据的长度打印出来

substr

select substr(name,1,3) from students; #name字段从1的位置向后截取3位打印出来	例如David -->Dav
select substr(name,2,3) from students; #name字段从2的位置向后截取3位打印出来	例如David -->avi

注意:sql的下标是从1开始

concat

select concat(name,‘123‘) from students; #将students表的所有name字段的数据后面拼接123打印出来	例如David -->David123

replace

select replace(name,‘a‘,‘666‘) from students; #将students表的所有name字段的数据中的a替换为666 例如David -->D666vid

ifnull

select ifnull(hobby,‘学习‘) from students #判断,如果hobby字段的值是null的用学习替换

round & ceil & floor

select round(score) from students #四舍五入取整
select round(score,1) from students #四舍五入,保留一位小数
select ceil(score) from students #向上取整 7.1 --> 8
select floor(score) from students #向下取整 7.9 --> 7

now

select now() #现在的年与日,时分秒
select curdate() #现在的年月日
select curtime() #现在的时分秒

year & month & day

select year(now()) #取现在的年
select month(now()) #取现在的月
select day(now()) #取现在的日

hour()时&minute()分&second()秒

select hour(now()) #取现在的时
select minute(now()) #取现在的分
select second(now()) #取现在的秒

SQL的基础函数

原文:https://www.cnblogs.com/fangweicheng666/p/15142633.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!