数据库常用函数汇总

去除重复行: distinct
select distinct math form student


转换成大小写字母: upper() lower()
select id,upper(name) from from student


将首字母转换成大写字母:initcap()
select id,initcap(name) from from student


字符串连接:concat() or ||
select id,concat(id,name),birth from student or
select id || name from student


sql查询语句时,可以在列后空一行,然后写出别名 或者使用as + 别名:
select id, name, math 数学成绩 from student
selcet id, name, math as 数学成绩 from student


字符串截取方法:substr(字符串,起始位置,[长度])
select substr('helloworld',3) from dual ------> loworld
select substr('helloworld',3,6) from dual ------> loworl


判断字符串1在字符串2第一次出现的位置instr(字符串1,字符串2)
select instr('hellohello','ll') from dual -------> 2


trim() 去除字符串两端的空格:
trunc()取整:
mod()取余数
round()四舍五入


替换字符串函数 repleace(串1,串2,串3),将串1中的串2替换成串3:
select repleace('hello','o','O')------->hellO


将字符型的数据转换成日期型数据 to_date()
select to_date('1003-3-4','yyyy-mm-dd') from dual


判断替换字符串 nvl(串1,串2)如果串1是null,则用串2替换 
select name,nvl(math,0) as 数学成绩 from student




字符串补齐函数 lpad----左补齐 rpad---右补齐 
select lpad('name',10,'%')from dual------> %%%name%%%


count()统计数量
select count(id) from student


分组查询 group by
select classid from student group by classid having classid is not null


sum() 求和
avg()平均
max() 最大值
min() 最小值


内连接 关联查询select s.birth,s.age,c.math,c.name from student s ,class c where s.classid = c.id



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值