1、创建表
Sql代码
-
create table test(
-
id varchar2(10),
-
age number
-
);
2、备份表
Sql代码
-
create table
-
as
-
select * from test group by id;
3、删除表
Sql代码
-
drop table test;–删除表结构和表数据
4、清空表
Sql代码
-
truncate table test;–清空数据表数据,没有返回余地
-
delete from test;—清空数据表数据,有返回余地
5、添加字段下载
Sql代码
-
alter table test add (
-
name varchar2(10),
-
interest varchar2(20)
-
);
6、删除字段
Sql代码
-
alter table test drop name;
7、更新数据
7.1更新一条数据
Sql代码
-
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中查询完数据直接进入编辑模式更改数据
Sql代码
-
select * from test for update;
-
–备注:更新操作执行完,要锁上数据表,同时执行commit提交操作
8、查询数据
Sql代码
-
select * from test;
9、查询数据表数量
Sql代码 下载
-
select count(0) from test;
-
–备注:count(0)或者其他数字比count(*)更加节省数据库资源,高效快捷
10、插入数据
10.1插入一条数据中的多个字段
Sql代码
-
insert into test (C1,C2) values(1,‘技术部’);
Sql代码
-
insert into test(C1,C2) select C1,C2 from test_common;
-
commit;
10.2插入多条数据
Sql代码
-
insert into test(
-
id,
-
name,
-
age
-
)
-
select
-
id,
-
name,
-
age
-
from test_common;
-
commit;
-
–备注:1、插入多条数据时,insert into语句后面没有values,直接拼接数据查询语句;2、在oracle中对数据表进行了insert、update、delete等操作后,要执行commit提交,否则在系统处是禁止操作数据库的,因为此时数据库已经被锁死,这是数据库为了防止多人同时修改数据库数据造成混乱的一种防范机制。