oracle之单行函数之课后练习
18. 打印出 "2009年10月14日 9:25:40" 格式的当前系统的日期和时间.select to_char(sysdate, 'YYYY"年"MM"月"DD"日" HH:MI:SS')from dual 注意: 使用双引号向日期中添加字符19. 格式化数字: 1234567.89 为 1,234,567.89select to_char(1234567.89, '999,999,999.99')from dual20. 字符串转为数字时1). 若字符串中没有特殊字符, 可以进行隐式转换:select '1234567.89' + 100from dual2). 若字符串中有特殊字符, 例如 '1,234,567.89', 则无法进行隐式转换, 需要使用 to_number() 来完成select to_number('1,234,567.89', '999,999,999.99') + 100from dual21. 对于把日期作为查询条件的查询, 一般都使用 to_date() 把一个字符串转为日期, 这样可以不必关注日期格式select last_name, hire_datefrom employeeswhere hire_date = to_date('1998-5-23', 'yyyy-mm-dd')
-- where to_char(hire_date,'yyyy-mm-dd') = '1998-5-23'22. 转换函数: to_char(), to_number(), to_date()23. 查询每个月倒数第 2 天入职的员工的信息. select last_name, hire_datefrom employeeswhere hire_date = last_day(hire_date) - 124. 计算公司员工的年薪--错误写法: 因为空值计算的结果还是空值select last_name, salary * 12 * (1 + commission_pct) year_salfrom employees--正确写法select last_name, salary * 12 * (1 + nvl(commission_pct, 0)) year_salfrom employees25. 查询部门号为 10, 20, 30 的员工信息, 若部门号为 10, 则打印其工资的 1.1 倍, 20 号部门, 则打印其工资的 1.2 倍, 30 号部门打印其工资的 1.3 倍数--使用 case-when-then-else-endselect last_name, department_id, salary, case department_id when 10 then salary * 1.1when 20 then salary * 1.2when 30 then salary * 1.3end new_salfrom employeeswhere department_id in (10, 20, 30)--使用 decodeselect last_name, department_id, salary, decode(department_id, 10, salary * 1.1,20, salary * 1.2,30, salary * 1.3) new_salfrom employeeswhere department_id in (10, 20, 30)
1. 显示系统时间(注:日期+时间)
a) select to_char(sysdate,'yyyy-mm-dd hh:mi:ss')
b) from dual
2. 查询员工号,姓名,工资,以及工资提高百分之20%后的结果(new salary)
a) select employee_id,last_name,salary,salary*1.2 "new salary"
b) from employees
3. 将员工的姓名按首字母排序,并写出姓名的长度(length)
a) select last_name,length(last_name)
b) from employees
c) order by last_name asc
4. 查询各员工的姓名,并显示出各员工在公司工作的月份数(worked_month)。
a) select last_name,hire_date,round(months_between(sysdate,hire_date),1) workded_month
b) from employees
5. 查询员工的姓名,以及在公司工作的月份数(worked_month),并按月份数降序排列
a) Select last_name,hire_date,round(months_between(sysdate,hire_date),1) workded_month
b) from employees
c) order by workded_month desc
6. 做一个查询,产生下面的结果
<last_name> earns <salary> monthly but wants <salary*3>
Dream Salary
King earns $24000 monthly but wants $72000
select last_name || ' earns '|| to_char(salary,'$999999')||' monthly,but wants '||to_char(3*salary,'$999999') "Dream Salary"
from employees
7. 使用decode函数,按照下面的条件:
job grade
AD_PRES A
ST_MAN B
IT_PROG C
SA_REP D
ST_CLERK E
产生下面的结果
Last_name Job_id Grade
king AD_PRES A
select last_name "Last_name",job_id "Job_id",decode(job_id,'AD_PRES','A','ST_MAN','B', 'IT_PROG','C', 'SA_REP','D', 'ST_CLERK','E') "Grade"
from employees
8. 将第7题的查询用case函数再写一遍。
a) select last_name "Last_name",job_id "Job_id",case job_id when 'AD_PRES'then 'A'
b) when 'ST_MAN' then 'B'
c) when 'IT_PROG' then 'C'
d) when 'SA_REP' then 'D'
e) when 'ST_CLERK' then'E' end "Grade"
f) from employees
oracle之单行函数之课后练习相关推荐
- Oracle(二)单行函数
Oracle(二)单行函数 --单行函数 ---字符函数 select upper('yes') from dual;--YES select lower('YES') from dual;--yes ...
- ORACLE:单行函数
目录 一.函数介绍 二.函数分类 2.1 字符函数 lower.upper.initcap concat.substr.length.instr.lpad.rpad.trim.replace 2.2 ...
- 数据库 day60,61 Oracle入门,单行函数,多表查询,子查询,事物处理,约束,rownum分页,视图,序列,索引
1. oracle介绍 ORACLE数据库系统是美国ORACLE公司(甲骨文)提供的以分布式数据库为核心的一组软件产品,是目前最流行的客户/服务器(CLIENT/SERVER)或B/S体系结构的 ...
- oracle之单行函数之分组函数之课后练习
33. 查询 employees 表中有多少个部门select count(distinct department_id)from employees 34. 查询全公司奖金基数的平均值(没有奖金的人 ...
- oracle之单行函数之多表查询值之课后练习
26. 多表连接查询时, 若两个表有同名的列, 必须使用表的别名对列名进行引用, 否则出错!27. 查询出公司员工的 last_name, department_name, cityselect la ...
- oracle之单行函数之子查询课后练习2
1. 查询和Zlotkey相同部门的员工姓名和雇用日期 a) select last_name,hire_date b) from employees c) where department_id = ...
- oracle之单行函数之子查询之课后练习
/*************************************************************************************************/ ...
- oracle之单行函数之分组函数
--分组函数 select avg(salary),max(salary),min(salary),sum(salary) from employees 运行结果 --判断大小 select max( ...
- oracle之单行函数1
--全部小写 全部大写 全部首字母大写 select lower('ATGUIGUJAVA'),UPPER('ATGUIGU Java'),initcap('ATGUIGU Java') from d ...
最新文章
- iOS开发JSON字符串和字典互转
- C# 中SqlParameter类的使用方法小结
- 蓝桥杯-最短路(floyd算法)
- PHP学习笔记4:字符串与正则
- java字符串的常量池
- Javascript闭包与作用域
- 用Unity3D实现简单的牧师与魔鬼游戏(动作分离版)
- python导入不在同一路径的函数_python语言基础都有哪些
- 0分配不到地址_前端学习计算机网络——IP地址的划分及其分类
- emoji表情引发的JNI崩溃
- 《Cortex-M0权威指南》之体系结构---嵌套中断控制器(NVIC)
- 解决 screen 连接不上,提示“There is no screen to be resumed matching 18352.” 的问题
- Python实训第一天--基础知识
- Linux uname命令
- CRM系统部署阶段和实施战略
- python语言包含的错误_Python3十大经典错误及解决办法
- 《数据挖掘导论》读书笔记(一) -27
- 前端经典面试题(60道前端面试题包含JS、CSS、React、网络、浏览器、程序题等)
- steam++工具箱
- JavaScript+css实现的喜庆活动邀请函多页面html源码
热门文章
- QNetworkRequest 请求类
- [导入]使用SqlCommand对象执行存储过程
- java中同步组件_Java并发编程(自定义同步组件)
- java swing 串口_ComTest 接收串口数据,并显示在文本框内,通过JavaSwing实现 Develop 265万源代码下载- www.pudn.com...
- mac php oracle11g,Oracle11G函数整理
- linux 轻量化图形界面,YOXIOS 入门教程--基于Linux的 轻量化GUI图形系统和硬件平台(41页)-原创力文档...
- java打印数组_Java中打印数组内容的方式有哪些?
- 2018清华计算机类专业录取分数线,清华大学2018年各省录取分数线及各专业录取分数线 - 高教网...
- 数据结构杂谈(六)——队列
- 让你的WordPress主题支持自定义菜单