一、掌握oracle数据库的安装
二、Oracle中常用数据类型 字符类型 数值类型 日期类型 LOB类型
三、Oracle伪列包含 ROWNUM、ROWID
四、SQL语言分为DDL、DCL、TCL和DML
五、SQL函数分为 单行函数 分组函数 分析函数
六、mysql和oracle的不同?
七、

1、分页查询 rownum

  1. 查询中间数据
  1. --分页查询,查询中间数据
  2. select * from(
  3. select e.*,rownum rn from emp e) e1
  4. where e1.rn>=2 and e1.rn<=4;
  5. --查询员工表中的薪水,由高到低的5-9条数据
  6. select * from (
  7. select e1.*,rownum rn from(
  8. select * from emp e0 order by e0.sal desc) e1 )e2
  9. where e2.rn>=5 and e2.rn<=9;
  10. select * from stuinfo s;

2、去重

  1. --不重复显示学员姓名和年龄distinct
  2. select distinct stuname,stuage from stuinfo;

3、排序

  1. --按照姓名升序,姓名相同按年龄降序排序
  2. select * from stuinfo order by stuname asc ,stuage desc;

4、取别名

  1. --起别名 中文或者特殊字符加双引号
  2. select stuname "姓名",stuage"年 龄" from stuinfo;

5、创建新表—3种方法

  1. --创建新表1 复制表的结构和记录
  2. create table stuinfo1 as select * from stuinfo;
  3. select * from stuinfo1;
  4. drop table stuinfo1;
  5. --创建新表2 用选定的列创建新表
  6. create table stuinfo2 as select stuname , stuage from stuinfo;
  7. select * from stuinfo2;
  8. drop table stuinfo2;
  9. --创建新表3 只复制结构不复制记录
  10. create table stuinfo3 as select * from stuinfo where 1=2;
  11. select * from stuinfo3;
  12. drop table stuinfo3;

6、不重复或重复取一条数据

  1. --按照姓名和年龄分组,找出不存在重复的记录
  2. select stuname,stuage,max(stuno)
  3. from stuinfo group by stuname,stuage
  4. having count(stuname||stuage)=1;
  5. --重复的姓名和年龄,只保留一条数据
  6. select s.*,rowid from stuinfo s;
  7. delete from stuinfo where rowid not in(
  8. select max(rowid) from stuinfo
  9. group by stuname,stuage);

7、连接符

  1. --连接操作符 ||看成字符串连接的+
  2. --查询emp表,查询两个字段并连接在一起
  3. select e.job||'_'||e.ename
  4. from emp e;

8、联合 union

  1. --创建表,emp-->表emp42
  2. create table emp42 as select * from emp;
  3. select * from emp42;
  4. update emp42 set empno=8934 where empno=7934;
  5. --联合 union 重复的只显示一次,不重复的全显示
  6. select * from emp
  7. union
  8. select * from emp42;

9、联合所有 union all

  1. --联合所有 union all 无论是否重复,2 个表的数据全部显示
  2. select * from emp
  3. union all
  4. select * from emp42;

10、交集 intersect

  1. --交集 intersect 显示公共的部分
  2. select * from emp
  3. intersect
  4. select * from emp42;

11、减集 minus

  1. --减集 minus 显示第一张表-第二张表不重复的数据
  2. select * from emp
  3. minus
  4. select * from emp42;
  5. --只显示两表不同的部分,先联合所有,再去重

12、函数

(1)、日期函数 to_date

  1. --日期函数 字符串转日期
  2. select to_date('2021-4-6','yyyy-mm-dd') from dual;
  3. select 3+2 from dual;
  4. --sysdate 返回当前时间
  5. select sysdate from dual;

(2)、字符函数 to_char

  1. --字符函数 将日期转字符串
  2. select to_char(sysdate,'yyyy-mm-dd HH24:mi:ss') from dual;

(3)、数字函数 to_number

  1. --数字函数 将字符串转数字 sqrt()开平方
  2. select sqrt( to_number('25')) from dual;

(4)、滤空函数

  1. --滤空函数 过滤空值 --为空就是+0 --不为空就是工作+奖金,为空即是基本工资
  2. select ename,
  3. sal+nvl(comm,0) sal1,
  4. nvl2(comm,sal+comm,sal) sal2,
  5. decode(to_char(hiredate,'MM'),'01','一月','02','二月','03','三月'
  6. ,'04','四月','05','五月','06','六月''下半年')
  7. from emp;

(5)、分析函数

—rank 1-1-3 并列间隔排名
—dense_rank 1-1-2 并列无间隔
—row_number 1-2-3 无并列无间隔

  1. --分析函数 相当于分组group by 排名时能用 partition 按照什么进行分组
  2. --rank 1-1-3 并列间隔排名
  3. --dense_rank 1-1-2 并列无间隔
  4. --row_number 1-2-3 无并列无间隔
  5. select ename,deptno,sal,
  6. rank() over(partition by deptno order by sal desc) "rank",
  7. dense_rank() over(partition by deptno order by sal desc) "dense_rank",
  8. row_number() over(partition by deptno order by sal desc) "rn"
  9. from emp;
  1. select e.*,rownum,rowid from emp e;
  2. --分页查询,查询中间数据
  3. select * from(
  4. select e.*,rownum rn from emp e) e1
  5. where e1.rn>=2 and e1.rn<=4;
  6. --查询员工表中的薪水,由高到低的5-9条数据
  7. select * from (
  8. select e1.*,rownum rn from(
  9. select * from emp e0 order by e0.sal desc) e1 )e2
  10. where e2.rn>=5 and e2.rn<=9;
  11. select * from stuinfo s;
  12. --不重复显示学员姓名和年龄distinct
  13. select distinct stuname,stuage from stuinfo;
  14. --按照姓名升序,姓名相同按年龄降序排序
  15. select * from stuinfo order by stuname asc ,stuage desc;
  16. --起别名 中文或者特殊字符加双引号
  17. select stuname "姓名",stuage"年 龄" from stuinfo;
  18. --创建新表1 复制表的结构和记录
  19. create table stuinfo1 as select * from stuinfo;
  20. select * from stuinfo1;
  21. drop table stuinfo1;
  22. --创建新表2 用选定的列创建新表
  23. create table stuinfo2 as select stuname , stuage from stuinfo;
  24. select * from stuinfo2;
  25. drop table stuinfo2;
  26. --创建新表3 只复制结构不复制记录
  27. create table stuinfo3 as select * from stuinfo where 1=2;
  28. select * from stuinfo3;
  29. drop table stuinfo3;
  30. --按照姓名和年龄分组,找出不存在重复的记录
  31. select stuname,stuage,max(stuno)
  32. from stuinfo group by stuname,stuage
  33. having count(stuname||stuage)=1;
  34. --重复的姓名和年龄,只保留一条数据
  35. select s.*,rowid from stuinfo s;
  36. delete from stuinfo where rowid not in(
  37. select max(rowid) from stuinfo
  38. group by stuname,stuage);
  39. --连接操作符 ||看成字符串连接的+
  40. --查询emp表,查询两个字段并连接在一起
  41. select e.job||'_'||e.ename
  42. from emp e;
  43. --创建表,emp-->表emp42
  44. create table emp42 as select * from emp;
  45. select * from emp42;
  46. update emp42 set empno=8934 where empno=7934;
  47. --联合 union 重复的只显示一次,不重复的全显示
  48. select * from emp
  49. union
  50. select * from emp42;
  51. --联合所有 union all 无论是否重复,2 个表的数据全部显示
  52. select * from emp
  53. union all
  54. select * from emp42;
  55. --交集 intersect 显示公共的部分
  56. select * from emp
  57. intersect
  58. select * from emp42;
  59. --减集 minus 显示第一张表-第二张表不重复的数据
  60. select * from emp
  61. minus
  62. select * from emp42;
  63. --只显示两表不同的部分,先联合所有,再去重
  64. --函数
  65. --日期函数 字符串转日期
  66. select to_date('2021-4-6','yyyy-mm-dd') from dual;
  67. select 3+2 from dual;
  68. --sysdate 返回当前时间
  69. select sysdate from dual;
  70. --字符函数 将日期转字符串
  71. select to_char(sysdate,'yyyy-mm-dd HH24:mi:ss') from dual;
  72. --数字函数 将字符串转数字 sqrt()开平方
  73. select sqrt( to_number('25')) from dual;
  74. --滤空函数 过滤空值 --为空就是+0 --不为空就是工作+奖金,为空即是基本工资
  75. select ename,
  76. sal+nvl(comm,0) sal1,
  77. nvl2(comm,sal+comm,sal) sal2,
  78. decode(to_char(hiredate,'MM'),'01','一月','02','二月','03','三月'
  79. ,'04','四月','05','五月','06','六月''下半年')
  80. from emp;
  81. --分析函数 相当于分组group by 排名时能用 partition 按照什么进行分组
  82. --rank 1-1-3 并列间隔排名
  83. --dense_rank 1-1-2 并列无间隔
  84. --row_number 1-2-3 无并列无间隔
  85. select ename,deptno,sal,
  86. rank() over(partition by deptno order by sal desc) "rank",
  87. dense_rank() over(partition by deptno order by sal desc) "dense_rank",
  88. row_number() over(partition by deptno order by sal desc) "rn"
  89. from emp;