PLSQL事务

 1 使用set transaction设置事务属性
 2 只读事务 set transaction read only
 3 读写事务 set transaction write;
 4 在进行数据统计分析工作时,一般都会查询数据库中的多个表,此时可以将查询统计
 5 工作定义为只读事务, 防止进行DML操作
 6 --只读事务示例
 7 declare
 8       v_1981 number(2);
 9       v_1982 number(2); 10 v_1983 number(2); 11 begin 12 commit; 13 set transaction read only name '统计年度入职数据'; 14 select count(empno) into v_1981 from emp where 15 to_char(hiredate,'yyyy')='1981'; 16 select count(empno) into v_1982 from emp where 17 to_char(hiredate,'yyyy')='1982'; 18 select count(empno) into v_1983 from emp where 19 to_char(hiredate,'yyyy')='1983'; 20 commit; 21 dbms_output.put_line('1981年入职人数:'||v_1981); 22 dbms_output.put_line('1982年入职人数:'||v_1982); 23 dbms_output.put_line('1983年入职人数:'||v_1983); 24 end; 25 26 27 --不同块中的异常作用域级别 28 declare 29  e_outerexception exception; 30 begin 31 declare 32  e_innerexception exception; 33 begin 34  raise e_innerexception; 35  raise e_outerexception; 36 end; 37 --raise e_innerexception; --在外层异常出发内存块异常时非法的 38 --外层异常覆盖内层异常 39  exception raise e_outerexception; 40 when others then 41 dbms_output.put_line('出现了错误'||'错误编号' 42 ||SQLCODE||'错误名称'||sqlerrm); 43 end; 44 --exception_init使用示例 把Oracle系统异常关联到我们自定义异常 45 declare 46  e_missingnull exception; 47 pragma exception_init (e_missingnull,-1400); 48 begin 49 insert into emp(empno) values(null); 50 commit; 51 exception 52 when e_missingnull then 53 dbms_output.put_line('触发了ORA-1400错误!'||sqlerrm); 54 rollback; 55 end;

 

 

转载于:https://www.cnblogs.com/Remedy/p/8093906.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值