查詢
select *|列名|運算式 from 表名 where 條件 order by 列名
select t.* from STUDENT.STUINFO t where t.stuname = '李四';
select t.stuid,t.classno,t.stuaddress,t.grade from STUDENT.STUINFO t where t.stuname = '李四';
select t.* from STUDENT.STUINFO t where t.classno = 'C201801' ORDER BY T.AGE ASC;
備份查詢資料
create table 表名 as select 陳述句
create table student.stuinfo2 as select * from student.stuinfo;
select * from student.stuinfo2;
插入
insert into 表名(列名1,列名2,列名3.....) values(值1,值2,值3.....);
insert into STUDENT.STUINFO (STUID, STUNAME, SEX, AGE, CLASSNO, STUADDRESS, GRADE, ENROLDATE, IDNUMBER)
values ('SC201801005', '龍七', '1', 26, 'C201801', '福建省廈門市XXX號', '2018', to_date('01-09-2018', 'dd-mm-yyyy'), '3503021992XXXXXXXX');
select * from student.stuinfo t where t.stuid='SC201801005';
插入查詢結果
INSERT INTO 表名 SELECT 子句
delete from student.stuinfo t where t.stuid in (select b.stuid from student.stuinfo2 b);
insert into student.stuinfo select * from student.stuinfo2;
select * from student.stuinfo;
更新
update 表名 set 列名1=值1,列名2=值2,列名3=值3... where 條件
update student.stuinfo t set t.age = '24', t.idnumber = '3503021994XXXXXXXX' where t.stuname = '張三';
commit;
select * from student.stuinfo t where t.stuname='張三';
通過查詢結果更新
update 表1 set 列名=(select 列名 from 表2 where 表1.列名=表2.列名)
where exists (select 1 from 表2 where 表1.列名=表2.列名)
update student.stuinfo t
set (age, idnumber) = (select age, idnumber from student.stuinfo2 b where b.stuid = t.stuid)
where exists (select 1 from student.stuinfo2 b where b.stuid = t.stuid and b.stuname = '張三');
select *from student.stuinfo t where t.stuname='張三';
洗掉
delete from 表名 where 條件
delete from stuinfo t where t.stuname='張三';
截斷表
truncate table 表名
truncate table stuinfo2;
洗掉和截斷的區別
- TRUNCATE 是 DDL 命令,命令執行完就提交,洗掉的資料不能恢復; DELETE 命令是 DML 命令,命令執行完需提交后才生效,洗掉后的資料可以通過日志檔案恢復,
- TRUNCATE 的執行速度比 DELETE 速度快很多,
- TRUNCATE 會重置索引,DELETE 不會,
- DELETE 會觸發觸發器,TRUNCATE 不會,
- DELETE 的原理是一條一條從表中洗掉資料,并將洗掉操作當做事務記錄在資料庫日志中,可以回滾;TRUNCATE 是一次性將資料頁洗掉,不能回滾,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/14917.html
標籤:Oracle
上一篇:[學習筆記] Oracle欄位型別、建表陳述句、添加約束
下一篇:Could not find archived log for sequence 587 thread 1 under default destinations SQL
