- 2023-03-26 12:05:53
- 4865 热度
- 0 评论
----------////////////////// 通用函数 ////////////////////////------------- --nvl函数 如果 exp1 为空,则返回 exp2 Select nvl(comm,0) From emp --nullif函数 如果 exp1 和 exp2 相等,则返回 null ,否则返回 exp1 Select nullif(1,2) From dual --nvl2函数 如果 exp1 不为空,则返回 exp2 ,否则返回 exp3 Select empno,ename,sal,comm,nvl2(comm,sal+comm,sal) total From emp --coalesce函数 遇到非空即返回 Select empno,ename,sal,comm,coalesce(sal+comm,sal,0) total From emp --case函数 Select empno,ename,sal, Case deptno When 10 Then '财务部' When 20 Then '研发部' When 30 Then '销售部' Else '未知部门' End 部门 From emp; --decode函数 Select empno,ename,sal, decode(deptno,10,'财务部', 20,'研发部', 30,'销售部', '未知部门' ) 部门 From emp; --多行子查询,子查询返回不是一个结果的 Select * From emp Where sal>Any(Select Avg(sal) From emp Group By deptno); Select * From emp Where sal>All(Select Avg(sal) From emp Group By deptno); Select * From emp Where job In (Select job From emp Where ename='MARTIN' Or ename='SMTTH') --分页查询第一种写法 select * from ( select rownum no,e.* from ( select * from emp order by sal Desc ) e where rownum<=5 ) where no>=3; --分页查询第二种写法 select * from ( select rownum no,e.* from ( select * from emp order by sal Desc ) e ) where no>=3 and no<=5; --随机返回五行数据 Select * From ( Select empno,ename,job From emp Order By dbms_random.value() ) Where Rownum <= 5; Select * From emp Order By sal --首字母转为大写 Select initcap(ename) From emp --连接字符串 Select concat('hello ','word') From dual --截取字符串 Select substr(ename,-3,3) From emp --四舍五入 Select round(789.567,-2) From dual --直接取几位,不四舍五入 Select trunc(789.576,-2) From dual --雇佣了几周 Select round((Sysdate-hiredate)/7) From emp --年 月 日 Select empno,ename,to_char(hiredate,'yyyy') Year,to_char(hiredate,'mm') months,to_char(hiredate,'dd') Day From emp --格式化为制定时间格式 Select empno,ename,to_char(hiredate,'yyyy-mm-dd') From emp --去零 Select empno,ename,to_char(hiredate,'fmyyyy-mm-dd') From emp --美元 Select empno,ename,to_char(sal,'$99,999') From emp --本地 Select empno,ename,to_char(sal,'L99,999') From emp --年薪资 (工资+奖金)×12 Select empno,ename,nvl(comm,0),(sal+nvl(comm,0))*12 income From emp --奖金不为空 Select Distinct job From emp Where comm Is Not Null --每月倒数第三天雇佣的员工信息 Select * From emp Where Last_day(hiredate)-2=hiredate --最高12年前雇佣的,今天和雇佣日期之间总月份/12 Select * From emp Where months_between(Sysdate,hiredate)/12 > 12 --雇佣了多少天 Select ename,round(Sysdate-hiredate) From emp Select * From emp --工作年限,月限 Select ename,trunc(months_between(Sysdate,hiredate)/12) Year, trunc(Mod(months_between(Sysdate,hiredate),12)) months From emp
以上代码仅供参考
0 评论
留下评论
热门标签
- Spring(403)
- Boot(208)
- Spring Boot(187)
- Spring Cloud(82)
- Java(82)
- Cloud(82)
- Security(60)
- Spring Security(54)
- Boot2(51)
- Spring Boot2(51)
- Redis(31)
- SQL(29)
- Mysql(25)
- Dalston(24)
- IDE(24)
- mongoDB(22)
- MVC(22)
- JDBC(22)
- IDEA(22)
- Web(21)
- CLI(20)
- Alibaba(19)
- SpringMVC(19)
- Docker(17)
- SpringBoot(17)
- Git(16)
- Eclipse(16)
- Vue(16)
- JPA(15)
- Apache(15)
- ORA(15)
- Tomcat(14)
- Linux(14)
- HTTP(14)
- Mybatis(14)
- Oracle(14)
- jdk(14)
- OAuth(13)
- Nacos(13)
- Pro(13)
- XML(13)
- JdbcTemplate(13)
- JSON(12)
- OAuth2(12)
- Data(12)
- int(11)
- Myeclipse(11)
- stream(11)
- not(10)
- Bug(10)
- Hystrix(9)
- ast(9)
- maven(9)
- Map(9)
- Swagger(8)
- APP(8)
- Bit(8)
- API(8)
- session(8)
- Window(8)
- windows(7)
- too(7)
- HTML(7)
- Github(7)
- JavaMail(7)
- Cache(7)
- File(7)
- IntelliJ(7)
- mail(7)
- Server(6)
- nginx(6)
- jar(6)
- ueditor(6)
- ehcache(6)
- UDP(6)
- RabbitMQ(6)
- and(6)
- star(6)
- Excel(6)
- Log4J(6)
- pushlet(6)
- apt(6)
- Freemarker(6)
- read(6)
- WebFlux(6)
- JSP(6)
- Bean(6)
- error(6)
- are(5)
- SVN(5)
- for(5)
- DOM(5)
- Sentinel(5)
- the(5)
- JWT(5)
- rdquo(5)
- PHP(5)
- Struts(5)
- string(5)
- script(5)