How to make a program insert a piece of data every few seconds in PL/SQL
In writing ORACLE PL/SQL, if you need to pause program execution for a few seconds before continuing execution, you can do this through oracle's built-in dbms_lock.sleep, but the dbms_lock package needs to be installed by the user.
[root@oraclevm ~] # su-oracle
[oracle@oraclevm ~] $sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon May 25 16:36:12 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0-64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL > startup
SQL > @? / rdbms/admin/dbmslock.sql
Package created.
Synonym created.
Grant succeeded.
SQL > grant execute on dbms_lock to public;-- Grant PUBLIC execution permissions
Grant succeeded.
SQL > create table test1 (id number,name varchar2 (40), time date);-- create test1 temporary table
Table created.
SQL > select * from test1;-No data
No rows selected
SQL > SET TIMING ON-- Open time display
SQL > begin-- start executing the test script
2 insert into test1 (id,name,time) values (1)
3 DBMS_LOCK.SLEEP (10);-- Let the program hold for 10 seconds
4 insert into test1 (id,name,time) values (2 recorder Shirley Magazine Sysdate)
5 commit
6 end
7 /
PL/SQL procedure successfully completed.
Elapsed: 0010.04-program execution time is 10.04 seconds.
SQL > SELECT ID,NAME,TO_CHAR (TIME,'YYYY/MM/DD HH24:MI:SS') AS TIME FROM TEST1;
-- query execution results
ID NAME TIME
1 Andy 10:09:03 on 2014-12-10-the insertion time for the first item is 09:03
2 Shirley 10:09:13 on 2014-12-10-the insertion time for Article 2 is 09:13
It's like the first one is 10 seconds late.
SQL > drop table test1
Table dropped.
Here's an example:
Insert a piece of data every other second
Vi / tmp/11.sh
# / bin/sh
Su-oracle