1、創建表
create table test(
id varchar2(10),
age number
);
2、備份表
create table
as
select * from test group by id;
3、刪除表
drop table test;--刪除表結構和表數據
4、清空表
truncate table test;--清空數據表數據,沒有返回餘地
delete from test;---清空數據表數據,有返回餘地
5、添加字段下載
alter table test add (
name varchar2(10),
interest varchar2(20)
);
6、刪除字段
alter table test drop name;
7、更新數據
7.1更新一條數據
update test t
set t.id='001'
where t.id is not null;
commit;
7.2從其他表更新多條數據
Sql代碼 下載
update test t set t.name=(
select tm.name
from test_common tm
where t.id=tm.id
);
commit;
--備註:update數據時,最好將update子查詢中的sql單獨建表,提高更新速度。
7.3在PL/SQL中查詢完數據直接進入編輯模式更改數據
select * from test for update;
--備註:更新操作執行完,要鎖上數據表,同時執行commit提交操作
8、查詢數據
select * from test;
9、查詢數據表數量
Sql代碼 下載
select count(0) from test;
--備註:count(0)或者其他數字比count(*)更加節省數據庫資源,高效快捷
10、插入數據
10.1插入一條數據中的多個字段
insert into test (C1,C2) values(1,'技術部');
insert into test(C1,C2) select C1,C2 from test_common;
commit;
10.2插入多條數據
insert into test(
id,
name,
age
)
select
id,
name,
age
from test_common;
commit;
--備註:1、插入多條數據時,insert into語句後面沒有values,直接拼接數據查詢語句;2、在oracle中對數據表進行了insert、update、delete等操作後,要執行commit提交,否則在系統處是禁止操作數據庫的,因爲此時數據庫已經被鎖死,這是數據庫爲了防止多人同時修改數據庫數據造成混亂的一種防範機制。