自定义函数比库函数速度快的例子

  • 来源: IT168 作者: sevenleaf   2010-07-02/11:17
  • 自定义函数比库函数速度快的例子
    create or replace and compile java source named "jmath"
    as
       import java.sql.*;
       import java.lang.Math.*;
      public class jmath
       {
      public static void main(String[] argv)
       {
       System.out.println("hello, java demo1");
       }
      public static int mod(int x,int y)
       {
       return x%y;
       }
      public static double log(double x,double y)
       {
       return java.lang.Math.log(y)/ java.lang.Math.log(x);
       }
      }
    /
    show errors java source "jmod"
    create or replace procedure jmain
    as
    language java name 'jmath.main(java.lang.String[])';
    /
    create or replace function jmod(x in number,y in number)
    return number
    as
    language java name 'jmath.mod(int ,int )return int';
    /
    create or replace function jlog(x in number,y in number)
    return number
    as
    language java name 'jmath.log(double ,double )return double';
    /
    call dbms_java.set_output(5000);
    call jmain();
    select sum(log(10,rownum)) from t;
    select sum(jlog(10,rownum)) from t;
    SQL> select sum(log(10,rownum)) from t;
    SUM(LOG(10,ROWNUM))
    -------------------
             5565708.92
    已用时间:  00: 00: 15.72
    SQL> select sum(jlog(10,rownum)) from t;
    SUM(JLOG(10,ROWNUM))
    --------------------
              5565708.92
    已用时间:  00: 00: 04.88


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多