学数据库这么久了?SQL数据库基础函数都搞懂了吗?安排

同步滚动:关

学数据库这么久了?SQL数据库基础函数都搞懂了吗?安排

文章插图
 
SQL的基础函数lowerselect lower(name) from students #将students表的所有name字段的数据全都转为小写打印出来upperselect upper(name) from students #将students表的所有name字段的数据全都转为大写打印出来lengthselect length(name) from students #将students表的所有name字段的数据的长度打印出来substr【学数据库这么久了?SQL数据库基础函数都搞懂了吗?安排】select substr(name,1,3) from students; #name字段从1的位置向后截取3位打印出来例如David -->Davselect substr(name,2,3) from students; #name字段从2的位置向后截取3位打印出来例如David -->avi注意:sql的下标是从1开始
concatselect concat(name,'123') from students; #将students表的所有name字段的数据后面拼接123打印出来 例如David -->David123replaceselect replace(name,'a','666') from students; #将students表的所有name字段的数据中的a替换为666 例如David -->D666vidifnullselect ifnull(hobby,'学习') from students #判断,如果hobby字段的值是null的用学习替换round & ceil & floorselect round(score) from students #四舍五入取整select round(score,1) from students #四舍五入,保留一位小数select ceil(score) from students #向上取整 7.1 --> 8select floor(score) from students #向下取整 7.9 --> 7nowselect now() #现在的年与日,时分秒select curdate() #现在的年月日select curtime() #现在的时分秒year & month & dayselect year(now()) #取现在的年select month(now()) #取现在的月select day(now()) #取现在的日hour()时&minute()分&second()秒select hour(now()) #取现在的时select minute(now()) #取现在的分select second(now()) #取现在的秒标签: [数据库]




    推荐阅读