Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make a program insert a piece of data every few seconds in PL/SQL

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report