【JSU】LJDragon's Oracle course notes In the first semester, junior year

DML数据操纵语言

DML指:update,delete,insert等语句

eg1:select语句

  1. select e.* from emp e where empno = 7369;

eg2:insert语句

--插入数据 insert into 表名 [(列1,列2,……)] values (值1,值2,……);

--省略列列表,默认就是表中的所有列

--列和值必须要个数,顺序,类型相同

  1. --增加一个新部门
  2. INSERT
    INTO departments (department_id,department_name,manager_id,location_id)
  3. VALUES (120,'NEC',206,1700);
  4.  
  5. INSERT
    INTO departments
  6. VALUES (120,'NEC',206,1700);
  7.  
  8. INSERT
    INTO departments (department_id,department_name)
  9. VALUES (120,'NEC');
  10.  
  11. INSERT
    INTO departments
  12. VALUES (120,'NEC',NULL,NULL);

--插入多行 insert into 表名 [(列1,列2,……)] 子查询;

  1. INSERT
    INTO new_dept
  2. SELECT * FROM dept;

eg3:update语句

--更新数据 update 表名 set 列1=值,列2=值,……[where 子句]

  1. update emp
  2. set sal = sal+500,
  3. hiredate = (hiredate + 30)
  4. where empno = 7902

--修改100员工的姓名为张三

  1. UPDATE new_emp
  2. SET first_name = '三',
  3.        last_name = '张'
  4. WHERE employee_id = 100;

--修改60号部门员工的工资上浮50元

  1. UPDATE new_emp
  2. SET salary = salary + 50
  3. WHERE department_id = 60;

--修改103号员工的工资和100号员工相同

  1. UPDATE new_emp
  2. SET salary = (SELECT salary
  3.                  FROM new_emp
  4.                  WHERE employee_id = 100)
  5. WHERE employee_id = 103;

eg4:清空/删除表

truncate table 表名

delete from 表名 where

--快速删除表,清空整个表

--不能带条件

--不记录日志

--删除表空间

--数据不能回滚

--(之前一直都用这个的)

--有带条件

--记录日志

--不删除表空间

--数据可以回滚

--清空学生表

  1. select * from stu_tmp;
  2. truncate
    table stu_tmp;

--删除数据 delete from 表名 [where 子句]

  1. --删除103员工
  2. DELETE
    FROM new_emp
  3. WHERE employee_id = 103;
  4.  
  5. --删除50号部门员工
  6. DELETE
    FROM new_emp
  7. WHERE department_id = 50;
  8.  
  9. --删除部门名称为IT的部门的员工
  10. DELETE
    FROM new_emp
  11. WHERE department_id = (SELECT department_id
  12.                         FROM departments
  13.                         WHERE department_name = 'IT');

eg5:合并表merge

merge into 副表表名 别名

using 主表表名 别名 on (主表.主键=副表.主键)

when matched then

更新语句

when not matched then

插入语句

  1. --创建两张员工表并合并
  2. SELECT employee_id,last_name,salary
  3. FROM employees;
  4.  
  5. SELECT employee_id,last_name,salary
  6. FROM employees;
  7.  
  8. --合并数据
  9. MERGE INTO emp2 e2
  10. USING emp1 e1 ON (e1.emp=e2.empno)
  11. WHEN MATCHED THEN--匹配上,则更新
  12.      UPDATE
    SET e2.ename=e1.ename,e2.sal=e1.sal
  13. WHEN
    NOT MATCHED THEN--没有匹配上,插入数据
  14.      INSERT
    VALUES (e1.empno,e1.ename,e1.sal)

dcl:grant,revoke

dql:select

ddl:create,drop,alter

tcl:commit,rollback

分析函数

--over函数连续求和

  1. select t1.empno,t1.sal,t1.deptno,
  2. (select
    sum(t.sal) from emp t where t.deptno = t1.deptno)
  3. as 工资总和
  4. from emp t1;
  5. --------------------------------
  6. select t1.*,
  7. (select
    sum(t.sal) from emp t where t.deptno = t1.deptno)
  8. as 工资总和
  9. from emp t1;

  1. SELECT empno,
  2.        sal,
  3.        deptno,
  4.        sum(sal) over() AS 总个表总和 , --总个表总和
  5.        sum(sal) over(order
    by empno) AS 累计显示 , --累计显示
  6.        sum(sal) over(partition by deptno) 工资总和1,
  7.        sum(sal) over(partition by deptno order
    by empno) 部门工资总和2
  8. FROM emp;

  1. SELECT empno,
  2.        sal,
  3.        deptno,
  4.        avg(sal) over() ,
  5.        avg(sal) over(partition by deptno)
  6.        from emp;

  1. SELECT empno,
  2.        sal,
  3.        deptno,
  4.        sum(sal) over(ORDER BY deptno) over1,
  5.        SUM(sal) over() over2
  6. FROM emp;

 

ORACLE STUDY NOTES 01的更多相关文章

  1. ORACLE STUDY NOTES 02

    [JSU]LJDragon's Oracle course notes In the first semester, junior year I.用户和权限 1.用户操作 --创建新用户 CREATE ...

  2. Machine Learning Algorithms Study Notes(3)--Learning Theory

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  3. Machine Learning Algorithms Study Notes(2)--Supervised Learning

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  4. Machine Learning Algorithms Study Notes(1)--Introduction

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1    Introduction    1 1.1    ...

  5. Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(3)

    Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(3) 一.配置共享存储 [oracle@aix203 ~]$lsdev -c disk hdisk0 Available ...

  6. Oracle Study之--Oracle 11gR2通过RMAN克隆数据库

    Oracle Study之--Oracle 11gR2通过RMAN克隆数据库 Purpose of Database Duplication A duplicate database is usefu ...

  7. Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(4)

    Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(4) 一.安装CRS补丁 在安装CRS之前,须要安装补丁p6718715_10203_AIX64-5L,否则在安装时会出现 ...

  8. Oracle Study之--Oracle 单实例11.2.0.1.0升级到11.2.0.3.0

    Oracle Study之--Oracle 单实例11.2.0.1.0升级到11.2.0.3.0 系统环境: 操作系统:RedHat EL6(64位) Oracle:    Oracle 11gR2 ...

  9. ORACLE 10.2.01升级10.2.05 for windows 详细文档

    最近要做一个数据库的升级工作,提前在自己的PC机上练习了一下,这种文档在网上很多,但是大多都是使用命令编辑脚本,其实数据库还有一个DBUA的升级工具可以使用,使升级工作方便了很多. OS环境:wind ...

随机推荐

  1. B/S架构的几种形式

    1. 什么是B/S架构 B/S架构的全称为Browser/Server,即浏览器/服务器结构.Browser指的是Web浏览器,极少数事务逻辑在前端实现,但主要事务逻辑在服务器端实现.B/S架构的系统 ...

  2. Android - 消息机制与线程通信

    以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删):http://blog.csdn.net/luosheng ...

  3. yii图片上传

    http://wuhai.blog.51cto.com/2023916/953300 首先感谢这里的博主,提供了思路,不过在调用 $model->b_image->extensionNam ...

  4. 【网络流#7】POJ 3281 Dining 最大流 - 《挑战程序设计竞赛》例题

    不使用二分图匹配,使用最大流即可,设源点S与汇点T,S->食物->牛->牛->饮料->T,每条边流量为1,因为流过牛的最大流量是1,所以将牛拆成两个点. 前向星,Dini ...

  5. mui实现自动登录

    <!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta name= ...

  6. 秒味课堂Angular js笔记------过滤器

    不同过滤器的小demo. currency number uppercase json limitTo date orderBy filter <script> var filterMy ...

  7. mysql的replication(主从同步)总结

    很好的文章,对mysql的主从架构有深入理解. mysql主从同步,从master同步数据到slave慢的情况下,是不是可以改成多线程处理加快同步速度? 参考文章如下: MySQL Replicati ...

  8. 智能SQL优化工具--SQL Optimizer for SQL Server(帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 )

    SQL Optimizer for SQL Server 帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 SQL Optimizer for SQL Server 让 SQL Serve ...

  9. 制作ado开发辅助工具类SqlHelper

    public static class SqlHelper { //通过配置文件获取连接字符创 private static readonly string constr = Configuratio ...

  10. MyEclipse汉化后问题

    今天为了教学生如何汉化MyEclipse10.7,所以讲IDE汉化了一下. 个人还是喜欢用英文版,所以就将D:\MyEclipse\MyEclipse 10目录下的配置文件myeclipse.ini里 ...