0% found this document useful (0 votes)
104 views

Implementing A PL/SQL Stored Procedure Concurrent Request APPENDIX 2: Sample Stored Procedure

The document describes a PL/SQL stored procedure that purges signon data from the fnd_logins table. It defines a test_package with a purge_signon_data procedure that accepts parameters for a user name, cutoff date, and error handling. The procedure opens a cursor to select matching records, deletes them within a loop, commits if any were deleted, and logs status and errors.

Uploaded by

sivakrishna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

Implementing A PL/SQL Stored Procedure Concurrent Request APPENDIX 2: Sample Stored Procedure

The document describes a PL/SQL stored procedure that purges signon data from the fnd_logins table. It defines a test_package with a purge_signon_data procedure that accepts parameters for a user name, cutoff date, and error handling. The procedure opens a cursor to select matching records, deletes them within a loop, commits if any were deleted, and logs status and errors.

Uploaded by

sivakrishna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Author – A.

Kishore
http://appsdba.info

Implementing a PL/SQL Stored Procedure Concurrent


Request

APPENDIX 2: Sample Stored Procedure


Package Specification
/*
|| PACKAGE SPECIFICATION
*/
CREATE or REPLACE PACKAGE test_package
IS
/*
|| PROCEDURE: purge_signon_data
|| PURPOSE: delete rows from fnd_logins.
*/
PROCEDURE purge_signon_data
( errbuf OUT VARCHAR2
, retcode OUT NUMBER
, v_user_name IN VARCHAR2
, v_cutoff_date IN DATE );
END test_package;
/

Package Body
/*
|| PACKAGE BODY
*/
CREATE or REPLACE PACKAGE BODY test_package AS
/*
|| Implementation of purge_signon_data
*/
PROCEDURE purge_signon_data
( errbuf OUT VARCHAR2
, retcode OUT NUMBER
, v_user_name IN VARCHAR2
, v_cutoff_date IN DATE )

IS
v_num_recs_deleted NUMBER := 0; -- records deleted
v_username VARCHAR2(100); -- user name
v_login_id NUMBER := 0; -- login id
v_text_msg VARCHAR2(100); -- text message
v_error_code NUMBER; -- error code
v_error_message VARCHAR2(255); -- error message
CURSOR purge_signon_cursor ( v_user_name VARCHAR2,
v_cutoff_date DATE )
IS
SELECT fu.user_name
, fl.login_id
FROM fnd_user fu
Author – A.Kishore
http://appsdba.info

, fnd_logins fl
WHERE fu.user_id = fl.user_id
AND fu.user_name = UPPER(v_user_name)
AND fl.start_time < v_cutoff_date;
BEGIN
errbuf := NULL;
retcode := 0;
/*
|| Open cursor, fetch each record that meets selection criteria,
|| delete each record that meets selection criteria and commit
|| changes.
*/
fnd_file.put_line (fnd_file.log
, 'Beginning Procedure purge_signon_data');
fnd_file.put_line (fnd_file.log, '');
fnd_file.put_line (fnd_file.log
, 'User Name: ' || v_user_name);
fnd_file.put_line (fnd_file.log
, 'Cutoff Date: ' || v_cutoff_date);
fnd_file.put_line (fnd_file.log, '');
OPEN purge_signon_cursor ( v_user_name, v_cutoff_date );
LOOP
FETCH purge_signon_cursor INTO v_username, v_login_id;
EXIT WHEN purge_signon_cursor%NOTFOUND;
DELETE FROM fnd_logins
WHERE login_id = v_login_id;
v_num_recs_deleted := v_num_recs_deleted + 1;
END LOOP;
CLOSE purge_signon_cursor;
IF v_num_recs_deleted > 0 THEN
COMMIT;
v_text_msg := 'Total Records Deleted: '
|| TO_CHAR (v_num_recs_deleted, '999,999');
ELSE
v_text_msg := 'No Records Matched Selection Criteria';
END IF;
fnd_file.put_line (fnd_file.log, v_text_msg);
fnd_file.put_line (fnd_file.log, '');
fnd_file.put_line (fnd_file.log
, 'Ending Procedure purge_signon_data');
EXCEPTION
/*
|| Catch all error.
*/
WHEN OTHERS THEN
ROLLBACK;
v_error_code := SQLCODE;
v_text_msg := 'Fatal Error, Oracle Error is: '
|| TO_CHAR (v_error_code, '99999');
fnd_file.put_line (fnd_file.log, v_text_msg);
v_error_message := SQLERRM;
fnd_file.put_line (fnd_file.log, v_error_message);
Author – A.Kishore
http://appsdba.info

END purge_signon_data; -- end


END test_package; -- end test_package
/
Author – A.Kishore
http://appsdba.info
Author – A.Kishore
http://appsdba.info
Author – A.Kishore
http://appsdba.info

You might also like