操纵数据(DML)
数据操纵语言:当添加、更新或者删除数据库中的数据时需要使用 DML 语句。DML 依据的一个集合构成了一个被称为事务的逻辑单元。
------------------------------------------------------------------
添加一个新行到表中:
insert into+表(列名1,列名2,,列名n) values(值1,值2,,值n);
![50b034526fa94fac809c9d7d4d5a1ca7.png](https://i-blog.csdnimg.cn/blog_migrate/fbc4898d6f5c4046f62de17ec3b95928.png)
完全列添加
insert into+表 +values (表对应的列1,表对应的列2,,表对应的列n);列名可以省略不写,需要插入且顺序一致) 。
插入带空值的行
insert into departments (department_id, department_name, manager_id, location_id) values (310,'A',null,null);
隐式方法: 省略字段列表中的列。省略不需要插入值的列和需要插入的值
insert into departments (department_id, department_name) values (310,'A');
插入日期值:插入现在时间 sysdate
比如这个时间2005-5-5--> 05-5月-06 或者 to_date('2005-5-5','yyyy-mm-dd')
从另一个表中复制行
- 用一个查询写 INSERT 语句
- 不用 VALUES 子句
- 在查询中列的数目要匹配 INSERT 子句中列的数目
指定列添加: insert into +表名(需插入的列1,列2,,列n) +查询到的别的表中的列
insert into emp (id,name, salary, commission) select employee_id, last_name, salary, commission_pct from employees where job_id like'%REP%';
完全列添加:insert into +表名 +查询到的别的表中的列
insert into emp select employee_id,last_name,salary,commission_pct from employees where job_id like'%REP%';