oracle 锁、保存点实例

本文提供了一系列 Oracle SQL 的示例操作,包括表的创建、数据的插入与更新、事务管理及分区表的使用等。此外,还展示了如何通过设置保存点来实现部分回滚,以及如何使用序列自动生成ID。

drop table student
create table student(
id varchar2(10) primary key,
ename varchar2(20),
empno varchar2(5)
)
insert into student values(1,'张三','1001');
insert into student values(2,'李四','1002');
commit;
update student set ename='小小' where empno='1002';
select *from student;
--锁定整个表
select *from student for update;

--在一条语句已经处于锁定状态时,还继续执行nowait语句的话 那么就会抛出00054异常
select *from student for update nowait;
select *from student for update wait 5; --获取该数据,如果5秒后还未获取到,那么抛出异常


--显示事务、
drop table myemp;
create table myemp(
empno varchar2(10),
ename varchar2(10),
job varchar2(10),
birthday varchar2(10),
pay integer

)
select *from myemp;

insert into myemp values(1234,'张三','程序员',sysdate,10000);
savepoint sp_a;--设置一个保存点
insert into myemp values(4567,'李四','工程师',sysdate,20000);
savepoint sp_b;--设置一个保存点
commit;
delete from myemp;

rollback to sp_a;
rollback to sp_b;


create tablespace g_space01 datafile 'F:\tablespace\gr1.dbf' size 5M;
create tablespace g_space02 datafile 'F:\tablespace\gr2.dbf' size 5M;
create tablespace g_space03 datafile 'F:\tablespace\gr3.dbf' size 5M;
create tablespace g_space04 datafile 'F:\tablespace\gr4.dbf' size 5M;


drop table sales
create table sales(
product_id int,
sales_cost number(10)
)

partition by range( sales_cost)(
partition p1 values less than(100) tablespace g_space01,
partition p2 values less than(200) tablespace g_space02,
partition p3 values less than(300) tablespace g_space03,
partition p4 values less than(400) tablespace g_space04
)

select *from sales
--创建id 自增序列
create sequence seq_sales_product_id;
--插入海量数据
insert into sales seq_sales_product_id.nextval, DBMS_RANDOM.VALUE(0,299) from dual
connect by level <=4000000;
select *from sales;
select *from sales where sales_cost<100; --99990
select *from sales partition(p1);

 

转载于:https://www.cnblogs.com/KOAN-lcd/p/6681180.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值