Evidently, a one time only procedure is a concept used in PL/SQL for initializing variables, an anonymous PL/SQL code block defined without an "END" statement.
A PL/SQL one-time-only procedure is an anonymous block of code encapsulated within a package. The one time procedure is executed only once when the package is invoked for the first time in a user session.
Here is an example of a one time only procedure in PL/SQL. The end of a PL/SQL one time only procedure should be end of package body. In the example of a one tike only stored procedure below, note that the one time procedure only has one END statement instead of two:
CREATE OR REPLACE PACKAGE
package_name
AS
FUNCTION f_name ... ;
PROCEDURE p_name ... ;
END package_name;
/
CREATE OR REPLACE PACKAGE BODY
package_name
AS
FUNCTION f_name... BEGIN ... END f_name;
PROCEDURE p_name ... BEGIN ... END p_name;
BEGIN
-- whatever code is here executes one time only,
-- the first time the package is called
END package_name;
/
CREATE OR REPLACE PACKAGE pk_demo
AS
PROCEDURE p_proc_1;
FUNCTION f_func_1
RETURN NUMBER;
END pk_demo;
/CREATE OR REPLACE PACKAGE BODY pk_demo IS a NUMBER; FUNCTION f_func_1 RETURN NUMBER AS BEGIN RETURN 10; END f_func_1; PROCEDURE p_proc_1 IS li_num NUMBER; BEGIN SELECT f_func_1 INTO li_num FROM DUAL; DBMS_OUTPUT.put_line (li_num); END p_proc_1; //one-time-only procedure defination BEGIN DBMS_OUTPUT.put_line ('u r in the only block execution'); END pk_demo; /SQL> execute pk_demo.p_proc_1; you are in the only block execution 10 PL/SQL procedure successfully completed. //here in the following the output is not same as earlier SQL> execute pk_demo.p_proc_1; 10 PL/SQL procedure successfully completed.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15734550/viewspace-665435/ ,如需转载,请注明出处,否则将追究法律责任。