第十章 创建计算字段

来源:互联网 发布:面向对象编程的优点 编辑:程序博客网 时间:2024/06/05 14:39
--- 拼接字段 concat()
select concat(sname,score)  pj from student;


-- trim 去掉左右两边的空格
select trim(sname) from student;
select ltrim(sname) from student;
select rtrim(sname) from student;
-- 查询时 使用RTrim()函数 可以去掉右边空格 ltrim去掉左边空格 trim去掉左右两边空格
 
select left(sname,3) from student;
-- left(列名,最终位置) 返回串左边的字符


select right(sname,3) from student;
-- right(列名,右往左最终位置) 返回串左边的字符 


select length(sname) from student;
-- length(列名) 返回串长度


select student.sid, locate(sname,'qq5')from student;
-- locate(列名,'查找的student数据') 找出串的一个字串


select sid, substring(sname,2)from student;
-- substring(查询的列或者数据,查询位置) 返回字串的字符


select *,upper(sname)from student;
-- upper(列名或者数据)将串转换为大写
0 0