Dear friends,
Is possible commit inside functions?
Regards,
Hastha 23
5 20106
Dear friends,
Is possible commit inside functions?
Regards,
Hastha 23
Hi,
Ya. It is possible manually give commit in function. In java you can set commit by this.. - conn.setAutoCommit(true);
Thanks,
Srinivas r.
U can't commit within a function.
the function will compile but u get error at run time like this
"cannot perform a DDL, commit or rollback inside a query or DML"
but if u commit after the return statment it will compile and execute but the COMMMIT command will not execute because the control will return at the RETURN statment.
Dear friends,
Is possible commit inside functions?
Regards,
Hastha 23
Of course, you can commit inside a function. Also, you can execute ddl statements inside a function uing dynamic sql
Dear Hastha
Definitely we can use commit inside oracle function but programatically it's not a good practice to use commit inside oracle function because for performing DML operations we have oracle procedures. However i m providing below oracle function for ur reference in which commit has been used.
CREATE OR REPLACE FUNCTION commit_inside_func (pi_dml_opr_flag VARCHAR2)
RETURN NUMBER
IS
PRAGMA AUTONOMOUS_TRANSACTION;
po_rec_id NUMBER (10);
BEGIN
CASE
WHEN UPPER (pi_dml_opr_flag) = 'I'
THEN
INSERT INTO test_record
(rec_id, rec_desc
)
VALUES (test_record_sq.NEXTVAL, 'insert performed'
)
RETURNING rec_id
INTO po_rec_id;
WHEN UPPER (pi_dml_opr_flag) = 'U'
THEN
UPDATE test_record
SET rec_desc = 'update performed';
po_rec_id := SQL%ROWCOUNT;
WHEN UPPER (pi_dml_opr_flag) = 'D'
THEN
UPDATE test_record
SET rec_desc = 'delete performed',
rec_status = 'D';
po_rec_id := SQL%ROWCOUNT;
END CASE;
COMMIT;
RETURN (po_rec_id);
EXCEPTION
WHEN OTHERS
THEN
po_rec_id := NULL;
RETURN (po_rec_id);
END commit_inside_func;
I have used test_record table inside function as below
CREATE TABLE TEST_RECORD
(
REC_ID NUMBER(10),
REC_DESC NVARCHAR2(50),
REC_STATUS NVARCHAR2(1) DEFAULT 'A'
);
Regds
Bhushan
Dear Hastha
Definitely we can use commit inside oracle function but programatically it's not a good practice to use commit inside oracle function because for performing DML operations we have oracle procedures. However i m providing below oracle function for ur reference in which commit has been used.
CREATE OR REPLACE FUNCTION commit_inside_func (pi_dml_opr_flag VARCHAR2)
RETURN NUMBER
IS
PRAGMA AUTONOMOUS_TRANSACTION;
po_rec_id NUMBER (10);
BEGIN
CASE
WHEN UPPER (pi_dml_opr_flag) = 'I'
THEN
INSERT INTO test_record
(rec_id, rec_desc
)
VALUES (test_record_sq.NEXTVAL, 'insert performed'
)
RETURNING rec_id
INTO po_rec_id;
WHEN UPPER (pi_dml_opr_flag) = 'U'
THEN
UPDATE test_record
SET rec_desc = 'update performed';
po_rec_id := SQL%ROWCOUNT;
WHEN UPPER (pi_dml_opr_flag) = 'D'
THEN
UPDATE test_record
SET rec_desc = 'delete performed',
rec_status = 'D';
po_rec_id := SQL%ROWCOUNT;
END CASE;
COMMIT;
RETURN (po_rec_id);
EXCEPTION
WHEN OTHERS
THEN
po_rec_id := NULL;
RETURN (po_rec_id);
END commit_inside_func;
I have used test_record table inside function as below
CREATE TABLE TEST_RECORD
(
REC_ID NUMBER(10),
REC_DESC NVARCHAR2(50),
REC_STATUS NVARCHAR2(1) DEFAULT 'A'
);
Regds
Bhushan
In fact, if we use DML Operation inside a function, then this function cannot be used in the select clause of any query
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mark |
last post by:
If a java applicaiton using the type 4 driver calls a DB2 stored
procedure, does the stored procedure need to do its own commit when
updates are completed? If the stored procedure does a commit or...
|
by: Ugrasena via DBMonster.com |
last post by:
Hi team i am using DB2 7.2 on Windows2000.
We have lot many SQL Procedure Calls, is there any way i can Turn off the
Auto Commit on that Database, the Problem i have is many of our Application...
|
by: Henri Manson |
last post by:
Today I discovered that the following code fragment compiles under gcc 3.0
(even with the -ansi option) and doesn't compile under gcc 2.95. As far as I
know it's not allowed in C to declare...
|
by: No One |
last post by:
Here is my problem:
I have a certain set of well-defined manipulations that I have to apply
to different types of data. In all cases the manipulations are exactly the
same, and are to be...
|
by: Fernando Barsoba |
last post by:
Hi all,
I'm trying to reassign the address of a pointer inside a function and
return it once the function has done its things... However, the address
returned is not the address I wanted to...
|
by: darrel |
last post by:
Often, I want to use a string in multiple functions on a page. I can declare
and re-set the string in each function, or I can just delcare the string
outside of the individual functions so that...
|
by: kiss07 |
last post by:
Hi,
i want 2 and 3 rd max salary in a table .i want a single query.
please help..
Arun
|
by: Jess |
last post by:
Hello,
I learned that there are five kinds of static objects, namely
1. global objects
2. object defined in namespace scope
3. object declared static instead classes
4. objects declared...
|
by: amoldiego |
last post by:
Suppose I create one for loop for update statement . That updates arround 1000 rows .
So please tell me where i should place commit .
Inside the loop or outside the loop .
and how that improve...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |