Get execution time of sql script in oracle sqlplus

后端 未结 5 1108
既然无缘
既然无缘 2021-02-13 11:38

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 trie

5条回答
  •  爱一瞬间的悲伤
    2021-02-13 12:27

    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
    

提交回复
热议问题