数据操纵
主要是对表或视图进行插入(插入),修改(更新),删除(删除)操作。
分组统计查询
使用聚合函数需要注意的事项:
1. count(*)统计所有的记录数,数(字段名)字段值为null时列不统计
2。聚合函数的出现顺序
3。统计不重复的行信息的
[*字符函数*]
1。字符串连接的:concat (ch2, ch3)
返回字符串ch2与字符串ch3连接的字符串
如:
选择concat(“你好”,“世界!”)从双;,//hello world !
或
选择'你好' | | '世界!从双;,//hello world!
2.字符串首字母大写
initcap(char) :将字符串char中每个单词的首字母大写,其他字母小写
如: select initcap('hello,world') from dual ;//Hello,World 可以使用任何分隔符,进行分隔
3.字符索引位置:instr(ch2,ch3,[m[,n]])
返回指定字符串ch3在字符串ch2中的位置,m起始搜索位置,n表示ch3在ch2出现的次数
如:
select * from emp where instr(ename,'C')>0 ;//从1开始找
select * from emp where instr(ename,'c')=2 ;//查询出ename下标为2为'C'的员工
4.计算字符串的长度:length(char)
5.字符的大小写转换:
lower(char):把字符串char转换为小写
upper(char):把字符串char转换为大写
6.替换字符串:replace(ch2,ch3,ch4)
把字符串ch2中的字符串ch3替换成字符串ch4
如:select replace(sal,sal,'*****') from emp ;//把emp表中的员工的工资替换为*****
7.截取字符串:substr(ch,起始位置,截取多少位)
如:select substr('hello world',6,5) from dual ;//world
注:下标是从1开始的
8.去掉字符串空格
trim(char):去除两边的空格
ltrim(char,[ch]):去掉字符串左空格或去掉左边包含ch的字符串
select ltrim('abcdef','abc') from dual ;-->def,去除char左边包含abc的字母
rtrim(char,[ch]):去掉字符串右空格或去掉右边包含ch的字符串
select rtrim('abcdef','abc') from dual ;-->abc,去除char左边包含def的字母
9.instr(char1,char2,[m[,n]]) : 返回char2在char1中的位置,m表示起始索引位置,n表示cha2在char1出现的次数
select instr('abcde','d') from dual ;//下标从1开始查找,返回d所在字符串的位置,返回4
instr(char,char,n)【在一个字符串中搜索另一个字符串,n>0从前向后,你<0从后向前】
select instr('abcabc','c') from dual;-->3
select instr('abcabc','c',-1) from dual;-->6
10.chr(n):返回ASCII码值为n的字符
select CHR('65') from dual ;//A
ASCII(char):返回制定字符的ASCII码
select ascii('A') from dual;-->65--返回A字符的ASCII码
11.lpad(char1,n[,char2]):如果char1的长度大于n,那么返回char1左边n个字符,如果n大于char1的长度,使用
char2在char1左边填充使其长度达到n
select lpad('abc',2,'dd') from dual ;//ab--如果char1小于n的长度,直接输出n对应char1中的字符
select lpad('abc',5,'dd') from dual ;//ddabc
12.RPad(char1,n[,char2]):使用char2补充在char1右侧,使char1的长度达到n,如果n小于char1的长度,截掉后面多的部分
select rpad('abc',5,'a') from dual;-->abcaa
select rpad('abc',2) from dual;-->ab
select length(rpad('abc',5)) from dual;-->5【右边加多了2个空格】
13.Translate(char1,form,to):用to替换form,然后用form替换char1中匹配内容
select translate('abc','ab','a') from dual;--->ac
[日期函数]
1.dbtimezone:返回数据库所在的时区
从双重选择dbtimezone;
2。提取(离开日期):从日期日期中获取离开对应部分的内容,离开的取值可以有:
一年,月,日,小时,分钟,秒,timezone_hour, timezone_minute
timezone_region, timezone_abbr
从双重选择提取(从sysdate);//2016
3. add_months (d n):返回日期d添加n个月所对应的日期时间,n为正数表示d之后的日期,n为负数表示d之前的日期
选择add_months (sysdate, 2)从双重;//今天是2016-7-31日,加两个月,那么就是2016-9-30日
选择add_months (sysdate, 1)从双重;//今天是2016-8-1日,1代表上一个月,即是2016-7-1日
4. next_day(日期,星期几):
,,,,,,,,,参数说明:
,,,,,,,,,,,,,null