oracle sqlplus中获取sql脚本的执行时间

发布于 2024-12-20 04:33:07 字数 287 浏览 0 评论 0原文

我有一个脚本,用于将数据加载到 Oracle 中的表中(通过插入语句列表)。如何获取整个加载过程的执行时间?我尝试过settiming on,但这给了我每个插入语句的持续时间,而不是整个过程的持续时间。脚本如下所示:

spo load.log
prompt '**** load data ****'
set termout off
@@inserts.sql
commit;
set termout on
prompt '**** done ****'
spo off
exit;

I have a script that i use to load my data into my tables in Oracle (by a list of insert statements). How can i get the execution time of the entire loading process? I have tried with set timing on, but that gives me a duration for each insert statement and not the entire process. The script is shown below:

spo load.log
prompt '**** load data ****'
set termout off
@@inserts.sql
commit;
set termout on
prompt '**** done ****'
spo off
exit;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

听你说爱我 2024-12-27 04:33:07

不知道为什么每个人都把它弄得如此复杂。简单如下:

SQL> set timing on
SQL> select 1 from dual;

         1
----------
         1

1 row selected.

Elapsed: 00:00:00.00
SQL> 

Not sure why everybody is making it so complex. Simple as:

SQL> set timing on
SQL> select 1 from dual;

         1
----------
         1

1 row selected.

Elapsed: 00:00:00.00
SQL> 
删除会话 2024-12-27 04:33:07

这是一个老问题,但我找到了测量在 sqlplus 中运行脚本的时间的简单方法。您只需将其添加到脚本的开头

timing start timing_name

并将其添加到脚本的末尾。

timing stop

有关此命令的更多信息可以在 Oracle 的 SQL*Plus® 用户指南和参考中找到:收集时序统计数据

It old question but i have found easy way to measure time of running a script in sqlplus. You just have to add this on the beginning

timing start timing_name

And this on the end of a script

timing stop

More information about this command can be found at Oracle's SQL*Plus® User's Guide and Reference: Collecting Timing Statistics

北城半夏 2024-12-27 04:33:07

尝试一下,在开头添加以下内容,它会记住当前时间:

set serveroutput on
variable n number
exec :n := dbms_utility.get_time

在末尾添加以下内容,它会计算经过的时间:

exec :n := (dbms_utility.get_time - :n)/100
exec dbms_output.put_line(:n)

Try this, add the following at the beginning and it remembers the current time:

set serveroutput on
variable n number
exec :n := dbms_utility.get_time

Add this at the end and it calculates the time elapsed:

exec :n := (dbms_utility.get_time - :n)/100
exec dbms_output.put_line(:n)
べ繥欢鉨o。 2024-12-27 04:33:07

如果你在 Unix 上,你也可以这样做:

time sqlplus @inserts.sql

它会打印:

real    0m9.34s
user    0m2.03s
sys     0m1.02s

第一行给出了总执行时间。

If you are on Unix, you can also do it like that:

time sqlplus @inserts.sql

It will print:

real    0m9.34s
user    0m2.03s
sys     0m1.02s

The first line gives the total execution time.

瑕疵 2024-12-27 04:33:07

您所描述的本质上是一种审核脚本执行的方法。无论是经过的时间,还是要捕获的特定开始和结束时间,您都希望正确记录它们,以查看事情是否顺利(或者如果不顺利,为什么不顺利)。

这是一个类似于我们用于捕获和记录我们正在实施的所有数据库活动的模板。我们通过sqlplus.exe使用它来进行所有DDL更新(例如CREATE TABLE)以及插入到设置表中。

--Beginning of all SQL scripts:
set serveroutput on feedback on echo on verify on sqlblanklines on timing on define on
col time new_v v_time
col name new_v v_name
col user new_v v_user

select name, USER, to_char(sysdate, 'YYYYMMDD-HH24MISS') time  from v$database;

--Creates a new log file every time the script is run, and it's immediately
--obvious when it was run, which environment it ran in, and who ran it.
spool &v_time._&v_name._&v_user..log 

--Run the select again so it appears in the log file itself
select name, USER, to_char(sysdate, 'YYYYMMDD-HH24MISS') time  from v$database;

将您的作品主体放在这里。

--End of all SQL scripts:
select name, USER, to_char(sysdate, 'YYYYMMDD-HH24MISS') time  from v$database;
spool off

What you're describing is essentially a way to audit the script's execution. Whether it's an elapsed time, or specific start and end times you're capturing you want to log them properly to see if things went well (or if not, why not).

Here's a template similar to what we use for capturing and logging all database activity we are implementing. We use it via sqlplus.exe for all DDL updates (e.g. CREATE TABLE) and for inserts into setup tables.

--Beginning of all SQL scripts:
set serveroutput on feedback on echo on verify on sqlblanklines on timing on define on
col time new_v v_time
col name new_v v_name
col user new_v v_user

select name, USER, to_char(sysdate, 'YYYYMMDD-HH24MISS') time  from v$database;

--Creates a new log file every time the script is run, and it's immediately
--obvious when it was run, which environment it ran in, and who ran it.
spool &v_time._&v_name._&v_user..log 

--Run the select again so it appears in the log file itself
select name, USER, to_char(sysdate, 'YYYYMMDD-HH24MISS') time  from v$database;

Place the body of your work here.

--End of all SQL scripts:
select name, USER, to_char(sysdate, 'YYYYMMDD-HH24MISS') time  from v$database;
spool off
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文