In compiling PL/SQL, it may take several seconds to pause the program and continue execution. Check that dbms_lock.sleep (10) is provided in Oracle. However, you must install the dbms_lock package on your own, the demo is as follows:
- C: \ Documents entsAndSettings \ andyleng> sqlplus/nolog
- SQL * Plus: Release 11.2.0.1.0 ProductionOnThu Nov 10 10:04:56 2011
- Copyright (c) 1982,201 0, Oracle.AllRights reserved.
- SQL> conn/AsSysdba-- Log in as SYSDBA
- Connected.
- SQL> @? /Rdbms/admin/dbmslock. SQL-- Install the system package
- Package created.
- Synonym created.
- GrantSucceeded.
- SQL>Grant Execute OnDbms_lockTo Public;-- Grant PUBLIC execution permission
- GrantSucceeded.
- SQL>Create TableTest1 (id number,NameVarchar2 (40 ),Time Date);-- Create a temporary table named test1
- TableCreated.
- SQL>Select*FromTest1;-- No data
- No RowsSelected
- SQL>SETTIMINGON-- Enable time display
- SQL>Begin-- Start to execute the test script
- 2Insert IntoTest1 (id,Name,Time)Values(1,'And', Sysdate );
- 3 DBMS_LOCK.SLEEP (10 );-- Temporarily enable the program to take 10 seconds
- 4Insert IntoTest1 (id,Name,Time)Values(2,'Shirley', Sysdate );
- 5Commit;
- 6End;
- 7/
- PL/SQLProcedureSuccessfully completed.
- Elapsed: 00:00:10. 04-- The program execution time is 10.04 seconds.
- SQL>SELECTID,NAME, TO_CHAR (TIME,'Yyyy/MM/DD HH24: MI: ss')AS TIME FROMTEST1;-- Query execution results
- IDNAMETIME
- ---------------------------------------------------------------------
- 1 Andy 2011/11/10 10:09:03-- The First insert time is.
- 2 Shirley 10:10:13-- The insertion time of the second entry is, which is 10 seconds later than that of the first entry.
- Elapsed: 00:00:00. 00
- SQL>Drop TableTest1;
- TableDropped.
Custom EXCEPTION and GOTO usage:
- -- Create the procedure to loop del users.
- CREATE OR REPLACE PROCEDUREQA2_ATGCORE_MF.delBigTab
- AS
- PRAGMA AUTONOMOUS_TRANSACTION;
- P_Count NUMBER: = 1000;
- N_delete number: = 0;
- Start_timeDate: = Sysdate;
- End_timeDate;
- Var_usergroup number;
- E_nowait EXCEPTION;-- Custom exception
- PRAGMA EXCEPTION_INIT (e_nowait,-00054 );-- Error code that first caused the exception to "ORA-00054"
- BEGIN
- <Restart>-- Program tag
- WHILE 1 = 1
- LOOP
- Begin
- Var_usergroup: = QA2_ATGCORE_MF.DEL_USERGROUP_SEQ.nextval;
- EXECUTEIMMEDIATE
- 'Update QA2_ATGCORE_MF.DPS_USER_DEL_TEMP set usergroup_id =: usergroup, del_flag =''1'', Del_time = sysdate where del_flag =''0''And rownum <=: rn'
- USING var_usergroup, P_COUNT;
- IF (SQL % NOTFOUND)
- OR(TO_CHAR (SYSDATE,'Hh24mi')BETWEEN '123' AND '123')
- THEN
- EXIT;
- ELSE
- N_delete: = n_delete + SQL % ROWCOUNT;
- QA2_ATGCORE_MF.DEL_USERGROUP (var_usergroup );
- ENDIF;
- COMMIT;
- EXCEPTION
- WHENE_nowaitTHEN
- DBMS_LOCK.SLEEP (2 ););-- Wait 2 seconds before a ORA-00054 error occurs
- DBMS_OUTPUT.PUT_LINE (TO_CHAR (SYSDATE,'Yyyy/MM/DD HH24: MI: ss') | SQLCODE |':'| SQLERRM |'I am go to restart');
- GOTORestart;-- Jump to restart and re-execute the program when a ORA-00054 error occurs
- WHENOTHERSTHEN
- ROLLBACK;
- RAISE;
- END;
- ENDLOOP;
- COMMIT;
- End_time: = sysdate;
- DBMS_OUTPUT.PUT_LINE ('*************************************** ************************************');
- DBMS_OUTPUT.PUT_LINE ('Totally delete'| To_char (n_delete) |'Users! Used time :'| Numtodsinterval (end_time-start_time,'Day'));
- DBMS_OUTPUT.PUT_LINE ('*************************************** ************************************');
- END;
- /