How to suspend a program for a few seconds in the Pl/sql/sqlplus client

Source: Internet
Author: User
Tags sqlplus

1. How to check procedure exist:

Sql> Conn oper/oper123
Connected.
sql> desc Dbms_lock;
PROCEDURE Allocate_unique
Argument Name Type in/out Default?
------------------------------ ----------------------- ------ --------
Lockname VARCHAR2 in
Lockhandle VARCHAR2 out
Expiration_secs number in DEFAULT
FUNCTION CONVERT RETURNS Number (38)
Argument Name Type in/out Default?
------------------------------ ----------------------- ------ --------
ID number (+) in

2.

in writing PL/SQL, it is sometimes necessary to pause the program for a few seconds before proceeding, checking that Oracle has this feature built-in Dbms_lock.sleep (10), but the Dbms_lock package needs to be installed by the user, as shown below:

[SQL]View Plaincopy print?
  1. C:\Documents and Settings\andyleng>sqlplus/nolog
  2. Sql*plus:release 11.2.0.1.0 Production on Thu Nov 10:04:56
  3. Copyright (c) 1982, Oracle.  All rights reserved.
  4. Sql> Conn/as SYSDBA --Login as Sysdba
  5. Connected.
  6. Sql> @?/rdbms/admin/dbmslock.sql --Install the System Package
  7. Package created.
  8. Synonym created.
  9. Grant succeeded.
  10. Sql> Grant execute on dbms_lock to public ; --Authorize public to execute permissions
  11. Grant succeeded.
  12. sql> Create table test1 (ID number,name VARCHAR2 (+),time date); --Create test1 temporary table
  13. Table created.
  14. Sql> SELECT * from test1; --No data
  15. No rows selected
  16. sql> SET TIMING on --open time display
  17. Sql> begin --Start execution of test scripts
  18. 2 INSERT INTO test1 (ID,name, time) values (1,' Andy ', sysdate);
  19. 3 Dbms_lock.  SLEEP (10); --10 seconds for the program to be temporarily
  20. 4 INSERT INTO test1 (ID,name, time) values (2,' Shirley ', sysdate);
  21. 5 commit;
  22. 6 end;
  23. 7/
  24. PL/SQL procedure successfully completed.
  25. elapsed:00:00:10.04 --Program execution time is 10.04 seconds
  26. Sql> SELECT ID,Name,to_char (Time,' Yyyy/mm/dd HH24:MI:SS ') as time from TEST1; --Query execution Results
  27. ID NAME time
  28. ---------- ---------------------------------------- -------------------
  29. 1 Andy 2011/11/10 10:09:03 --The insertion time of the first one is 09:03
  30. 2 Shirley 2011/11/10 10:10:13 --The insertion time of the second one is 09:13, just 10 seconds later than the first one .
  31. elapsed:00:00:00.00
  32. sql> drop table test1;
  33. Table dropped.
C:\Documents and Settings\andyleng>sqlplus/nologsql*plus:release 11.2.0.1.0 Production on Thu Nov 10:04:56 2011Cop  Yright (c) 1982, Oracle. All rights reserved. Sql> conn/as SYSDBA--Login as Sysdba connected.sql> @?/rdbms/admin/dbmslock.sql--Install the system package created. Synonym created. Grant succeeded. Sql> Grant execute on dbms_lock to public; --Authorize public to execute permissions Grant succeeded.   Sql> CREATE TABLE test1 (ID number,name varchar2 (+), time date); --Create test1 temporary table created.  Sql> select * from Test1; --No data no rows selectedsql> SET TIMING on--open time display sql> Begin--Start Execution test script 2 insert into test1 (id,name,time) values  (1, ' Andy ', sysdate); 3 Dbms_lock.  SLEEP (10);  --Let the program temporarily 10 seconds 4 insert into test1 (id,name,time) VALUES (2, ' Shirley ', sysdate);  5 commit;  6 end; 7/pl/sql procedure successfully completed. elapsed:00:00:10.04--Program execution time is 10.04 seconds sql> SELECT id,name,to_char (timing, ' yyyy/mm/dd HH24:MI:SS ') as the from TEST1;                            --Query execution result ID NAME         Time---------------------------------------------------------------------1 Andy 2011/11/10 10:09:03--The insertion time of the first article is 09:03 2 Shirley 2011/11/10 10:10:1 3--The insertion time of the second is 09:13, just 10 seconds later than the first one elapsed:00:00:00.00sql> drop table test1; Table dropped.

How to suspend a program for a few seconds in the Pl/sql/sqlplus client

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.