我想测试的SQL语句的执行时间,我写的一个存储过程
create or replace procedure getruntime(time1 out VARCHAR2,time2 out VARCHAR2)
as        
begin
select to_char(systimestamp,'yyyy-mm-dd hh24:mi:ss.ff') into time1 from dual;
我这在写别的查询语句为什么说视图不存在啊?
  
select to_char(systimestamp,'yyyy-mm-dd hh24:mi:ss.ff') into time2 from dual;
        
end getruntime;有什么好方法取到SQL的执行时间吗

解决方案 »

  1.   

    是在sqlplus里吗?
    set timing on 
    SQL> set timing on;
    SQL> select count(*) from emp;  COUNT(*)
    ----------
            14已用时间:  00: 00: 00.12
      

  2.   


    SQL> explain plan for select * from dual;ExplainedSQL> select * from table(dbms_xplan.display
      2  );PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    Plan hash value: 3543395131
    --------------------------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    --------------------------------------------------------------------------8 rows selectedSQL> 
      

  3.   

    我是想在JAVA程序中取到一条SQL的执行时间。。
      

  4.   

    SQL> set timing on
    SQL> select * from dual;D
    -
    X已用时间:  00: 00: 00.03
    SQL>
      

  5.   

    用两次 System.currentTimeMillis(),然后相减即可
      

  6.   

    System.currentTimeMillis,这样不太准吧
      

  7.   


    那就恶心了,你必须的考虑网络的延时啊
    你在调用SQL 之前执行
    startTime = System.currentTimeMillis();
    execute sql_statement
    endTime = System.currentTimeMillis();最后两个去相减看可以不?
      

  8.   

     System.currentTimeMillis();
    测的时间不准啊
      

  9.   

    最好就是按你这种写法在数据库里得到执行时间,然后返回.貌似结果要转成varchar返回.
      

  10.   

    SQL> create or replace procedure pro_test_execute_time
      2  (o_str out varchar2)
      3  as
      4  time1 timestamp;
      5  time2 timestamp;
      6  v_num number;
      7  begin
      8   select systimestamp into time1 from dual;
      9   select count(*) into v_num from emp;
     10   select systimestamp into time2 from dual;
     11   o_str:=time2-time1;
     12  end;
     13  /
     
    Procedure created
     
    SQL> var str varchar2
    SQL> execute pro_test_execute_time(:str);
     
    PL/SQL procedure successfully completed
    str
    ---------
    +000000000 00:00:00.000000000
     
    SQL> 
    执行的真够快的..