SQL的基础函数

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 -->Davselect substr(name,2,3) from students; #name字段从2的位置向后截取3位打印出来 例如David -->avi
注意:sql的下标是从1开始
concat
select concat(name,"123") from students; #将students表的所有name字段的数据后面拼接123打印出来 例如David -->David123replace
select replace(name,"a","666") from students; #将students表的所有name字段的数据中的a替换为666 例如David -->D666vidifnull
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 --> 8select floor(score) from students #向下取整 7.9 --> 7now
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的基础函数 的全部内容, 来源链接: utcz.com/z/535842.html
