当前位置:网站首页>Significant differences between Oracle and Postgresql in PLSQL transaction rollback
Significant differences between Oracle and Postgresql in PLSQL transaction rollback
2022-08-04 03:35:00 【mingjie73】
相关
《Oracle/Mysql迁移到PostgresqlTransaction rollback behavior differences and transformation methods》
《Oracle与Postgresql在PLSQLSignificant difference in internal transaction rollback》
This difference is very easy to makeOracle迁移到PGThere is a major difference in the business logic after that.
1 总结
先放总结
- Oracle:在PLSQLInside if statement execution fails,After entering the exception handler,PL程序正常退出.Then before the execution of the failed statementSQL
不会回滚
,The execution results are submitted normally. - Postgresql:在PLPGSQLInside if statement execution fails,After entering the exception handler,PL正常退出.
那么整个PL内的所有SQL自动回滚
,因为:- PG不支持PL内写SAVEPOINT (OracleThere is an implicit before each statementsavepoint)
- PLThe whole is packaged in one big transaction.
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;
执行结果
边栏推荐
- XSS相关知识点
- 复现20字符短域名绕过
- "Introduction to nlp + actual combat: Chapter 8: Using Pytorch to realize handwritten digit recognition"
- 复制带随机指针的链表
- 张量篇-应用案例
- DIY电工维修如何拆卸和安装开关面板插座
- 安装postgis时报找不到“POSTGIS_VERSION”这个函数
- 异步编程解决方案 Generator生成器函数、iterator迭代器、async/await、Promise
- 网络工程师入门必懂华为认证体系,附系统学习路线分享
- MCU C language -> usage, and meaning
猜你喜欢
随机推荐
golang中的unsafe.Pointer,指针,引用
if,case,for,while
C language -- ring buffer
sqoop ETL tool
系统太多,多账号互通如何实现?
Hey, I had another fight with HR in the small group!
哎,又跟HR在小群吵了一架!
初识Numpy
元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存
目标检测-中篇
企业直播风起:目睹聚焦产品,微赞拥抱生态
docker+bridge+redis master-slave+sentry mode
There are too many systems, how to realize multi-account interworking?
Exclude_reserved_words 排除关键字
Shell 函数
MCU C language -> usage, and meaning
网络工程师入门必懂华为认证体系,附系统学习路线分享
Innovation and Integration | Huaqiu Empowerment Helps OpenHarmony Ecological Hardware Development and Landing
《nlp入门+实战:第八章:使用Pytorch实现手写数字识别》
uni-app 从零开始-基础模版(一)