distinct:去除重复行
例:select distinct math from student
order by 排序,升序---asc 降序—desc
例:select * from student order by mathdesc
select * fromstudent order by math, chinese
upper()转换成大写字母
例:select id, upper(name), birth, math fromstudent
Lower()转换成小写字母
例:select id, lower(name), birth, math fromstudent
Initcap()将首字母转换成大写字母
例:select id, initcap(name), birth, math fromstudent
Concat()字符串连接
例:select id, concat(id, name), birth, mathfromstudent
在oracle中使用“||”做字符串连接符
例:select id || name, birth, math fromstudent
oracle中在使用查询语句时,可以在列名后空一格,然后写出该列的别名,或者使用as关键字也可以为该列取别名。
例:select name, birth, math+10as math from student
selectname, birth, math+10 mathfromstudent
select name,birth, math+10 数学成绩from student
substr(字符串1,起始位置) 从字符串1中的“起始位置”开始截取,一直截取到最后,oracle中字符串的位置是从1开始数的。
例:select substr('helloworld',4) from dual
Substr(字符串1,起始位置,长度) 从字符串1中的“起始位置”开始截取,截取“长度”个字符串。
例:select substr('helloworld',3, 4) from dual
Instr(字符串1,字符串2 ) 判断字符串2在字符串1中第一次出现的位置
例:select instr('helloworld','o') from dual
Length(字符串1) 判断字符串1的长度
例: select name,length(name) from student
trim(字符串1) 去除字符串1左右两边的空格
例:select trim(' hellokitty ') afromdual
trim(字符串1 from 字符串2) 去除字符串2左右两边的字符串1
例:select trim('$' from '$$helloworld$$') from dual
trunc() 取整函数
例:select trunc(45.2) from dual
mod()取余数
例:select mod(12.1, 2) from dual
Round() 四舍五入
例:select round(3.1415926, 2) from dual
replace(字符串1, 字符串2,字符串3) 将字符串1中的字符串2替换成字符串3
例:select replace('helloworld','o', 'O') from dual
在oracle中字符类型的数据可以和数值类型的数据进行相互转换,字符类型的数据可以和日期类型的数据按照指定格式进行相互转换,日期类型的数据不能和数值类型的数据相互转换。
Oracle中默认的日期格式为“日-月-年”
例:insert into student (id, name, birth)values('113', 'Messi', '2-2ÔÂ-1970')
to_date(日期字符串, 格式) 将字符类型的数据转换成日期类型
例:select to_date('1970-02-02','yyyy-mm-dd') from dual
To_char(日期类型数据|数值类型数据,[格式]) 将日期或数值类型的数据转换成字符串
例:select to_char(sysdate, 'yyyy/mm/dd hh24:mi:ss') from dual
select to_char(1234)from dual
to_number(字符串) 将字符类型数据转换成数值
例:select to_number('123') from dual
add_months(日期, 数值) 在日期上面加月份
例:select add_months(to_date('1970-02-02','yyyy-mm-dd'), 2)fromdual
Months_between(日期1, 日期2) 查看两个日期之间相差的月份数
例:select trunc(months_between(sysdate, to_date('1970-02-02','yyyy-mm-dd'))) from dual
Last_day(日期) 查看日期所在月份的最后一天
例:select last_day(to_date('1970-02-02','yyyy-mm-dd')) from dual
nvl(字符串1,字符串2) 如果字符串1为null,那么用字符串2代替
例:select name, nvl(math, 0)+10 mathfrom student
nvl2(字符串1,字符串2,字符串3) 如果字符串1不为空,用字符串2代替,否则用字符串3代替
例:select name, nvl(math, 0)+10 mathfrom student
nullif(字符串1, 字符串2) 如果字符串1和字符串2相同,返回null,否则返回字符串1
例:select nullif('a','abc')from dual
Count() 统计数量
例:select count(id) from student
Group by 分组查询, 如果在分组之后想要加一些过滤条件,可以使用having
select classid, count(id) from student group byclassid having classidis not null
sum()求和
avg()平均分
max()最大值
min()最小值
内连接,两表之间根据某些条件进行查询
select s.id, s.name,s.birth, s.math, s.chinese, s.english, c.name,c.addressfrom student s, class c where s.classid=c.id