Hi All,
I am working with a database that uses a store procedure that calls a function in order to retrieve a "next id". I've been asked to combined the two by putting the logic of the function into the store procedure. After looking many different places on Tek-Tips and the Internet, I can't seem to find out whether or not it can be done.
Here is the function and stored procedure as they currently exists.
I was hoping that something like the below code could be done, but it doesn't work.
Any advice or pointing me in the right direction would be greatly appreciated.
Thanks,
Trey
I am working with a database that uses a store procedure that calls a function in order to retrieve a "next id". I've been asked to combined the two by putting the logic of the function into the store procedure. After looking many different places on Tek-Tips and the Internet, I can't seem to find out whether or not it can be done.
Here is the function and stored procedure as they currently exists.
Code:
CREATE OR REPLACE FUNCTION TCISP_GET_NEXT_ID
(F_ID_NAME IN CHAR,
F_BLOCK_SIZE IN NUMBER)
Return Number Is F_NEXT_ID NUMBER;
BEGIN
Select NEXT_ID + F_BLOCK_SIZE
Into F_NEXT_ID
From NEXT_IDS
Where ID_NAME = F_ID_NAME
For Update; --With(ROWLOCK)
-- adding 'NOWAIT' makes it a NoWait lock.
Return F_NEXT_ID;
EXCEPTION
When NO_DATA_FOUND Then
Return Null;
END;
/
CREATE OR REPLACE PROCEDURE TCISP_NEXT_ID
(F_ID_NAME IN CHAR,
F_BLOCK_SIZE IN NUMBER,
F_NEXT_ID OUT NUMBER)
AS
BEGIN
F_NEXT_ID := TCISP_GET_NEXT_ID(F_ID_NAME, F_BLOCK_SIZE);
If F_NEXT_ID Is Not Null Then
Update NEXT_IDS
Set NEXT_ID = F_NEXT_ID
Where ID_NAME = F_ID_NAME;
Commit;
End if;
EXCEPTION
When Others Then
Rollback;
END;
/
I was hoping that something like the below code could be done, but it doesn't work.
Code:
CREATE OR REPLACE PROCEDURE TCISP_NEXT_ID
(F_ID_NAME IN CHAR,
F_BLOCK_SIZE IN NUMBER,
F_NEXT_ID OUT NUMBER)
AS
BEGIN
Select NEXT_ID + F_BLOCK_SIZE
Into F_NEXT_ID
From NEXT_IDS
Where ID_NAME = F_ID_NAME;
Update NEXT_IDS
Set NEXT_ID = F_NEXT_ID
Where ID_NAME = F_ID_NAME;
Commit;
End if;
EXCEPTION
When Others Then
Rollback;
END;
Any advice or pointing me in the right direction would be greatly appreciated.
Thanks,
Trey