插入 +在包中提交
编写一个oracle包来实现记录持久化的最佳解决方案是什么? 我总是写这样的东西:
create or replace
PACKAGE BODY "USP_PRICELIST" AS
PROCEDURE usp_TABLE1Save
(
pErrorCode OUT NUMBER,
pMessage OUT VARCHAR2,
pPARAM1 IN CHAR,
pPARAM2 IN CHAR
)
IS
BEGIN
pErrorCode := 0;
INSERT INTO TABLE1
(PARAM1, PARAM2)
VALUES
(pPARAM1, pPARAM2);
EXCEPTION
WHEN OTHERS THEN pErrorCode := SQLCODE; pMessage := SQLERRM;
END usp_TABLE1Save;
END USP_PRICELIST;
我想知道在插入后是否必须提交。
阿尔贝托
what is the best solution to write a oracle package for record persistence?
I've always written something like this:
create or replace
PACKAGE BODY "USP_PRICELIST" AS
PROCEDURE usp_TABLE1Save
(
pErrorCode OUT NUMBER,
pMessage OUT VARCHAR2,
pPARAM1 IN CHAR,
pPARAM2 IN CHAR
)
IS
BEGIN
pErrorCode := 0;
INSERT INTO TABLE1
(PARAM1, PARAM2)
VALUES
(pPARAM1, pPARAM2);
EXCEPTION
WHEN OTHERS THEN pErrorCode := SQLCODE; pMessage := SQLERRM;
END usp_TABLE1Save;
END USP_PRICELIST;
and I was wondering if I have to COMMIT after the INSERT INTO.
Alberto
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不会在过程中进行提交,并将其留给调用该过程的代码。这允许该过程用作较大事务的一部分。插入不是隐式提交的。
I would not put a commit in the procedure, and leave that to the code that calls the procedure. This allows the procedure to be used as part of a larger transaction. The insert is not implicitly committed.
这实际上取决于您是否希望您的操作参与事务或原子操作。
It really depends on whether you want your operation to take part in a transaction or to be atomic.
请小心,如果您将提交放在包中,它将提交整个事务
Be careful, if you place the commit in the package it will commit the entire transaction
您还应该了解自主事务的概念
You should also look at the concept of autonomous transactions
默认情况下,Oracle 没有自动提交,因此您必须这样做。
By default Oracle has no auto-commit, so you have to.