星期四—练习数据库的基本函数

select * from EMP 
where job = 'CLERK'
or job = 'MANAGER'
and sal >= 1200; 
select * from EMP 
order by hiredate;
select * from EMP ,DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO;
--对sal这列进行升序
select * from EMP order by sal;
--对sal这列进行降序
select * from EMP order by sal DESC;
--插入列
select Upper('abcde'),sal+'1000' from EMP;
select lower('ABCDE'),sal+1000 from emp;
--改变字符的大小写
select * from emp where ename = upper('allen');
--
select initcap(ename)from emp;
--添加里面的内容
select concat('改了','吗?'),ename from emp;
--把内容进行减少
select substr('abcde',length('abcde')-2)from emp;
--表示处理字节的位置
select substr('412.313',0,2)from emp;
select substr('412.313',-2)from emp;
select substr('412.313',2)from emp;
--判断内容字节长度
select length(ename)from emp;
--把ename列的所有出现的A变成a
select replace(ename,'A','a')from emp;
--所在字符串的位置
select instr('Hello World','ld')from emp;
--左侧填充
select lpad('smith',10,'*')from emp;
--右侧填充
select Rpad('smith',10,'*')from emp;
--过滤首位空格
select trim('Mr smith')from emp;
--根据位置来判定数值
select round(412,1)from emp;
--四舍五入
select round(412.513,0)from emp;
select round(412.313,-2)from emp;
--取整
select trunc(412.53,2)from emp;
--当前月份到指定时间的月份
select months_between(sysdate,hiredate)from emp;
select months_between(to_date('2017-10-14','yyyy-mm-dd'),to_date('2017-08-12','yyyy-mm-dd'))from dual;
--当前月加1
select add_months(hiredate,1)from emp;
--跳转到下一个指定的星期
select next_day(sysdate,'星期二')from dual;
--定位到当月最后一天
select last_day(sysdate)from dual;
--获取当前时间
select sysdate from dual;
--获取年份
select to_char(sysdate,'yyyy')from dual;
--获取当前日期
select to_char(sysdate,'fmyyyy-mm-dd')from dual;
--把sal改成人民币格式
select to_char(sal,'L999999999')from emp;
--把当前的星期返回成数字
select to_char(sysdate,'D')from dual;
--计算两个数的加减乘除
select to_number('987')+to_number('14')from dual;
select to_number('258')-to_number('14')from dual;
select to_number('258')*to_number('14')from dual;
select to_number('2200')/to_number('4')from dual;
--把字符串转化成日期
select to_date('20170713','yyyymmdd')from dual;
--把null赋值为8
select nvl(comm,8) from emp;
--取余
select mod(9,5)from dual;
--所有有数值的数的平均
select avg(comm)from emp;
--所有数值的和
select sum(comm)from emp;
--每个月倒数第三天受雇的员工
select * from emp where last_day(hiredate)-2=hiredate; 
--25年前雇的员工
select * from emp where hiredate<=add_months(sysdate,-25*12);
--员工名字前面加Dear
select 'Dear'||initcap(ename)from emp;
--找出名字是5个字母的人
select * from emp where length(ename)=5; 
--找出名字中没有R的人
select * from emp where ename not like '%R_%'; 
--显示所有员工名字的第一个字
select substr(ename,0,1)from emp;
--名字按降序排列
select * from emp order by ename DESC;
--员工日工资
select sal/30 from emp;
--二月份入职的员工 
select * from emp where to_char(hiredate,'fmmm')='2';
各类数据库函数的使用

转载于:https://www.cnblogs.com/wx1691790309/p/7162281.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值