当前位置:网站首页>Oracle与Postgresql在PLSQL内事务回滚的重大差异
Oracle与Postgresql在PLSQL内事务回滚的重大差异
2022-08-04 03:30:00 【mingjie73】
相关
《Oracle/Mysql迁移到Postgresql事务回滚行为差异及改造方法》
《Oracle与Postgresql在PLSQL内事务回滚的重大差异》
这个差异点非常容易造成Oracle迁移到PG后业务逻辑出现重大差异。
1 总结
先放总结
- Oracle:在PLSQL内如果语句执行失败,进入异常处理程序后,PL程序正常退出。那么在执行失败语句前面的SQL
不会回滚
,执行结果都正常提交了。 - Postgresql:在PLPGSQL内如果语句执行失败,进入异常处理程序后,PL正常退出。
那么整个PL内的所有SQL自动回滚
,因为:- PG不支持PL内写SAVEPOINT (Oracle在每个语句前有隐式的savepoint)
- PL整体包装在一个大事务内。
Oracle11g
https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/static.htm#LNPLS598
2 测试用例Oracle11g
drop table employees;
create table employees(employee_id int, salary int, raise int, job_id varchar(16), last_name varchar(16), first_name varchar(16));
insert into employees values (1, 1000, 60, 'ST_CLERK', 'Geller', 'Rose');
insert into employees values (2, 2000, 100, 'ST_CLERK', 'Green', 'Rachel');
insert into employees values (3, 4000, 400, 'ST_AAAAA', 'Bing', 'Chanller');
insert into employees values (4, 6000, 630, 'AD_CLERK', 'Geller', 'Rose');
insert into employees values (5, 7000, 120, 'AD_DSFWR', 'Green', 'Rachel');
insert into employees values (6, 8000, 410, 'AD_AAAAA', 'Bing', 'Chanller');
DROP TABLE emp_name;
CREATE TABLE emp_name AS SELECT employee_id, last_name, salary FROM employees;
CREATE UNIQUE INDEX empname_ix ON emp_name (employee_id);
DECLARE
emp_id employees.employee_id%TYPE;
emp_lastname employees.last_name%TYPE;
emp_salary employees.salary%TYPE;
BEGIN
SELECT employee_id, last_name, salary
INTO emp_id, emp_lastname, emp_salary
FROM employees
WHERE employee_id = 1;
INSERT INTO emp_name (employee_id, last_name, salary) VALUES (100, emp_lastname, emp_salary);
INSERT INTO emp_name (employee_id, last_name, salary) VALUES (emp_id, emp_lastname, emp_salary);
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
DBMS_OUTPUT.PUT_LINE('Insert was rolled back');
END;
/
select * from emp_name;
结果
3 测试用例Postgresql14
drop table employees;
create table employees(employee_id int, salary int, raise int, job_id varchar(16), last_name varchar(16), first_name varchar(16));
insert into employees values (1, 1000, 60, 'ST_CLERK', 'Geller', 'Rose');
insert into employees values (2, 2000, 100, 'ST_CLERK', 'Green', 'Rachel');
insert into employees values (3, 4000, 400, 'ST_AAAAA', 'Bing', 'Chanller');
insert into employees values (4, 6000, 630, 'AD_CLERK', 'Geller', 'Rose');
insert into employees values (5, 7000, 120, 'AD_DSFWR', 'Green', 'Rachel');
insert into employees values (6, 8000, 410, 'AD_AAAAA', 'Bing', 'Chanller');
DROP TABLE emp_name;
CREATE TABLE emp_name AS SELECT employee_id, last_name, salary FROM employees;
CREATE UNIQUE INDEX empname_ix ON emp_name (employee_id);
select * from emp_name;
DO $$DECLARE
emp_id employees.employee_id%TYPE;
emp_lastname employees.last_name%TYPE;
emp_salary employees.salary%TYPE;
BEGIN
SELECT employee_id, last_name, salary
INTO emp_id, emp_lastname, emp_salary
FROM employees
WHERE employee_id = 1;
INSERT INTO emp_name (employee_id, last_name, salary) VALUES (100, emp_lastname, emp_salary);
INSERT INTO emp_name (employee_id, last_name, salary) VALUES (emp_id, emp_lastname, emp_salary);
EXCEPTION
WHEN others THEN
raise notice 'Insert was rolled back';
END$$;
select * from emp_name;
执行结果
边栏推荐
- JVM内存和垃圾回收-07.堆
- 自定义通用分页标签02
- 【医保科普】维护医保基金安全,我们可以这样做
- 4-way two-way HDMI integrated business high-definition video optical transceiver 8-way HDMI high-definition video optical transceiver
- FFmpeg —— 通过修改yuv,将视频转为黑白并输出(附源码)
- STM8S-----选项字节
- 三分建设,七分管理!产品、系统、组织三管齐下节能降耗
- sql语句查询String类型字段小于10的怎么查
- 查看mysql死锁语法
- Hey, I had another fight with HR in the small group!
猜你喜欢
一文看懂推荐系统:召回04:离散特征处理,one-hot编码和embedding特征嵌入
Architecture of the actual combat camp module three operations
【观察】超聚变:首提“算网九阶”评估模型,共建开放繁荣的算力网络
Hey, I had another fight with HR in the small group!
目标检测-中篇
案例 | 重庆银行流动数据安全挑战及应对实践
Development of Taurus. MVC WebAPI introductory tutorial 1: download environment configuration and operation framework (including series directory).
什么是数字孪生智慧城市应用场景
sqoop ETL tool
复制带随机指针的链表
随机推荐
Polygon zkEVM网络节点
怎么把elastic中的异常登录ip和日志自动导出或抓取到数据库中?
哎,又跟HR在小群吵了一架!
pnpm 是凭什么对 npm 和 yarn 降维打击的
一文看懂推荐系统:召回05:矩阵补充、最近邻查找,工业界基本不用了,但是有助于理解双塔模型
打造一份优雅的简历
【MD5】采用MD5+盐的加密方式完成注册用户和登录账号
kingbaseES V8R2/R3 表在指定表空间,为何显示为默认表空间?
逻辑漏洞----其他类型
SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropri
怎样提高网络数据安全性
STM8S-----option byte
Innovation and Integration | Huaqiu Empowerment Helps OpenHarmony Ecological Hardware Development and Landing
Polygon zkEVM network node
MRS: Introduction to the use of Alluxio
JVM内存和垃圾回收-07.堆
验证码业务逻辑漏洞
FFmpeg —— 通过修改yuv,将视频转为黑白并输出(附源码)
Exclude_reserved_words 排除关键字
单片机C语言->的用法,和意思