Oracle中DML语句
DML语句的使用
DML语句是数据库的操作语言,主要用来操作数据库的表,视图,一般情况下是指:select,update,insert,delete。
insert语句
------------------------------------------------- --插入值语法 insert into table_name (column1, column2, .. .) values (values1, values2, .. .) ------------------------------------------------- --无条件INSERT ALL insert all into sal_history values(EMPID,HIREDATE,SAL) into mrg_history values(EMPID,MGR,SAL) select employee_id EMPID,hire_date HIREDATE,salary SAL,manager_id MGR from employee where employee_id>200; ------------------------------------------------- --有条件INSERT ALL insert all --不论是否求值都为true when SAL>10000then into sal_history values(EMPID,HIREDATE,SAL) when MGE>200then into mrg_history values(EMPID,MGR,SAL) select employee_id EMPID,hire_date HIREDATE,salary SAL,manager_id MGR from employee where employee_id>200; ------------------------------------------------- --有条件的FIRST INSERT insert first --如果这个第一个when子句的求值为true,后面的when字句不会执行 --直到第一个满足条件为止 when SAL>2500then into special_sal values(DEPTID,SAL) when HIREDATE like ('%00%') then into hiredate_history_00 values(DEPTID,HIREDATE) when hiredate like ('%99%') then into hiredate_history_99 values(DEPTID,HIREDATE) else into hiredate_history values(DEPTID,HIREDATE) select department_id DEPTID,SUM(salary) SAL, MAX(hire_date) HIREDATE from employees GROUPBY department_id |
update语句
--更新表名 update table_name --更新的值 set column1 = values --限制条件 where state = '' |
delete语句
--选择删除数据 delete from customer --删除的限制条件 where customer_id='adc232' |
merge语句
merge语句作用: 1.在一个SQL语句中对表同时执行插入和更新操作 2.可以从一个或多个数据源中选择行来更新或插入一个或多个表 --1.省略条件update子句 merge into product p using newproducts np on(p.product_id = np.product_id) --当上面条件匹配 when matched then update set p.product_name = np.product_name, p.category = np.category; --2.省略条件insert子句 merge into product p using newproducts np on(p.product_id = np.product_id) --当上面条件匹配 when not matched then insert values (np.product_id,np.product_name,np_category); --3.带条件的update语句 merge into product p using newproduct np on (p.product_id = np.product_id) when matched then update set p.product_name = np.product_name where p.category = np.category; --4.带条件的insert和update语句 merge into product p using newproduct np on (p.product_id = np.product_id) --匹配到 when matched then update set p.product_name = np.product_name, p.category = np.category where p.category = 'DVD' --匹配不到 when not matched then insert values (np.product_id,np.product_name,np.category) where np.category != 'BOOKS'; --5.无条件insert merge into product p using newproduct np on (1 = 0) when not matched then insert values(np.product_id,np.product_name,np.category) where np.category = 'BOOKS'; --6.新加的delete功能 merge into product p using newproduct np on (p.product_id = np.product_id) when matched then update set p.product_name = np.product_name,p.category = np.category delete where (p.category = 'ELECARNCS') where not matched then insert values (np.product_id , np.product_name,np.category) |
truncate语句
truncate table 语句 作用:快速,无日志记录删除表中的所有行 和delete比较优点 a.所有的事物日志空间较少 b.表中不会留下任何页 |
Oracle中DML语句相关推荐
- oracle12测试骤,Oracle中SQL语句解析的步骤
我们都知道在Oracle中每条SQL语句在执行之前都需要经过解析,这里面又分为软解析和硬解析.那么这两种解析有何不同之处呢?它们又分别是如何进行解析呢?Oracle内部解析的步骤又是如何进行的呢?下面 ...
- Oracle编程入门经典 第6章 在Oracle中处理语句
6.1 SQL语句类别 DDL:数据定义语言语句.这样的语句有CREATE.TRUNCATE和ALTER,它们用于建立数据库中的结构,设置许可等.用户可以使用它们维护Oracle数据词典. D ...
- oracle不属于dml,Oracle中DML基础知识
DML(insert,update,delete) 1.插入数据 insert into 表名(列,列...)values(值,值...) //当插入的数据与表格一一对应时,列可以省略 insert ...
- oracle大于条件,oracle中sql语句中的in的条件数量大于1000有问题
oracle中sql语句中的in的条件数量大于1000有问题 oracle中sql语句中select * from t_Test t where t.Id in(1,2,3......)/*数量不能 ...
- 查询oracle 表达小,oracle中sql语句小练习(使用连接查询)
假设A(m,n,p),B(m,n,p) --1.A表中有某一项m而B表中没有 使用左连接查询: select a.* from A a left join B b on a.m=b.m where b ...
- oracle中into字句,oracle中into语句
oracle 中select into是什么意思 这是一个复制表数据的操作. 创建aaa表,这里没有定义aaa表的字段以及类型,而是用select * from bbb,这就是把bbb里面所有的字段包 ...
- oracle中sql语句(+)符号代表连接
oracle中sql语句(+)符号代表连接 (+)在=前边为右连接 (+)在=后边为左连接 SELECT a.*, b.* from a(+) = b就是一个右连接,等同于select a.*, b. ...
- oracle sql连接符号,Oracle中sql语句(+)符号代表连接的使用讲解
oracle中sql语句(+)符号代表连接 (+)在=前边为右连接 (+)在=后边为左连接 SELECT a.*, b.* from a(+) = b就是一个右连接,等同于select a.*, b. ...
- 三、oracle之DML语句
/*DML语句 对表中数据做增删改1.插入数据 1)insert into 表名 values(....)2)insert into (字段...) values(...)3)创建表的同时拷贝表的数据 ...
最新文章
- swift 浮点型字符串的运算
- 免息月供137元,新iPhone SE有7大理由值得买!但反对只需这1个就够了
- OpenvSwitch — 核心对象
- 已知圆心 坐标和一点坐标和角度 就之后的坐标_《6. AutoCAD 标注角度尺寸》
- serialVersionUID---java序列化
- JSON合并补丁:JSON-P 1.1概述系列
- 150万元重奖!阿里软件供应链安全大赛正式启动
- mysql-cluster5.7搭建集群(实际测试有效)
- 为什么要从 Microsoft Store 下载 Visual Studio/VS Code?
- 关于C语言运行时错误的原因的几个总结
- ppt太大如何压缩到最小,这个方法你得知道
- doxygen 教程 linux,使用Doxygen生成全中文的chm、pdf帮助文档的方法
- 复制瑞幸模式,出局的陆正耀再创业,要先开500家面馆
- 前端高效开发必备的 js 库
- 远程办公何时了,网络打洞帮你搞
- 关注电动汽车能效水平 提高续航能力
- 美国访问学者生活之行-开车租车及停车
- NoSQL 中的 CAP
- Robot Studio写字工作站
- rman如何直接备份到异地硬盘,磁带机和磁带库