七、sql基礎:1.DML語句--【Oracle資料庫】
阿新 • • 發佈:2019-01-10
####七、DML語句
Data Manipulation Language,資料操縱語言,增刪改。
#####1. INSERT語句
######1.1 格式一
insert into student (stu_id, stu_name) values(12, ‘zhao’);
######1.2 格式二
insert into student values (13, ‘xudong’ , null, null);
######1.3 格式三:從另一個表中Copy一行
insert into sales_reps (id, name, salary, commission_pot) select employee_id, last_name, salary, commission_pot from employees where job_id like '%REP%';
######1.4 格式四:使用子查詢作為插入目標
insert into
(select stu_id, stu_name, job_id from employees where stu_id = 100)
values (100, 'zhao', 12);
可以加上with check option來校驗
insert into
(select stu_id, stu_name, job_id from employees where stu_id = 100 with check option)
values (101, 'zhao', 12);
這樣插入的時候就會報錯,因為前面id=100,插入的是101
#####2. UPDATE語句
######2.1格式一:更新某些符合條件的行中的某些列為具體值
update student set stu_name = 'zhao', stu_sex = 2
where stu_id = 1 ;
######2.2格式二:使用子查詢的結果作為更新後的值
update student set class_name = (select class_name from class where class_id = 11) class_num = (select class_num from class where class_id = 11) where stu_id = 11;
#####3. DELETE語句
######3.1格式一:刪除某些符合條件的記錄
delect from student
where stu_id = 10;
######3.2格式二:刪除一張表中所有的記錄
delect from student;
truncate table student;語句也可以對錶進行清空,效率更快,但是不能回滾。
#####4. MERGE語句:比較、整合