Oracle Stored Procedure - UPDATE - Example
Source code to create and add sql update stored procedure to
catalog
The following example is for creating a simple update stored
procedure. You can run it through an explicit call from a host language
program or directly from a DBMS query execution shell like dbOrchestra.
CREATE OR REPLACE PROCEDURE SP_STUDENTS_UPDATE_BYPK
(
p_STUDENT_ID IN STUDENTS.STUDENT_ID%TYPE ,
p_ACTIVE_FLG IN STUDENTS.ACTIVE_FLG%TYPE
)
AS
BEGIN
UPDATE STUDENTS
SET
ACTIVE_FLG = p_ACTIVE_FLG
WHERE STUDENT_ID = p_STUDENT_ID ;
COMMIT ;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20001,
p_STUDENT_ID || ':$:' ||
p_ACTIVE_FLG || ':$:' ||
SQLERRM, TRUE) ;
END SP_STUDENTS_UPDATE_BYPK ;
/
It is important to note that for every column you include in the
update code you will need to enter data for. Typically, an sql update
stored procedure would be created for all the columns. There would be a
mapping layer that moves existing data to the exposed variables. In the
example provided I have created an update stored procedure that could be
tied directly to a function that would activate or inactivate a student.
Having an sql update stored procedure for this type of activity is
wholly rational and appropriate.
Executing the sql update stored procedure
Execute sql update stored procedure
To run the stored procedure you need to supply a values to the
applicable variables.
P_ACTIVE_FLG = 0
P_STUDENT_ID = 22
-------------------------------
P_ACTIVE_FLG IN NUMBER
P_STUDENT_ID IN NUMBER
#OBJECTTYPE=PROCEDURE#
#OWNER=COURSEREGISTRATION#
#OBJECT=SP_STUDENTS_UPDATE_BYPK#
#H2DB-END-OF-PROC#
Link to schema for Students table
|