oracle常规操作(一)

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从其他表更新多条数据

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、查询数据表数量
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提交,否则在系统处是禁止操作数据库的,因为此时数据库已经被锁死,这是数据库为了防止多人同时修改数据库数据造成混乱的一种防范机制。




 



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值