去除重复行: 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
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