使用Java Class,供一个自定义的Oracle Function来调用。
Oracle的特色之一在于它集成了一个优化了的JDK 1.1.8,由此可以使用Java Class来作非数据I/O的计算。Java has a rich toolkit for generating random numbers, in a class named "Random". 使用Java Class可以轻松地产生使用复杂算法产生的Random数和字符。

解决方案 »

  1.   

    谢谢楼上的,那么,采用java的话,怎么保证多用户并发的时候,random不会重复呢。
      

  2.   

    同意楼上的:)用PL/SQL写太烦了
      

  3.   

    to acmly() 
        存在表里,岂不是还要再访问数据库,那用java class还不如用pl/sql了。
      

  4.   

    The DBMS_RANDOM package provides a built-in random number generator utility. Oracle Corporation suggests that this package will run faster than generators written in PL/SQL itself because DBMS_RANDOM calls Oracle internal random number generator. Oracle describes this package as a relatively simple interface for a random number generator, limited to returning an 8-digit number. They recommend that you use the DBMS_CRYPTO_TOOLKIT package if you need a more sophisticated engine with more options. This package is available with Trusted Oracle.As with any random number generator, before you can obtain any random numbers from DBMS_RANDOM, you must first initialize the package by providing a seed number with DBMS_RANDOM抯 INITIALIZE procedure. You can later reseed the random number generator via RANDOM_SEED. When you need a random number, issue a call to the RANDOM, which returns a random number for your use. Finally, when you no longer need to use the random number generator, terminate DBMS_RANDOM via the TERMINATE procedure.The DBMS_RANDOM package is created when the Oracle database is first installed. The dbmsrand.sql script found in the built-in packages source code directory contains the source code for this package抯 specification. This script is called by catoctk.sql, which contains the scripts needed to use the PL/SQL Cryptographic Toolkit Interface. The scripts create the public synonym DBMS_RANDOM for the package and grant EXECUTE privilege on the package to public. All Oracle users can reference and make use of this package.DBMS_RANDOM does not declare any exceptions or nonprogram elements.---〉Example:
    DECLARE
       my_random BINARY_INTEGER;
    BEGIN
       DBMS_RANDOM.INITIALIZE (99999);
       for i in 1..10
       loop
         my_random := DBMS_RANDOM.RANDOM;
         dbms_output.put_line(to_char(my_random));
       end loop;
       DBMS_RANDOM.TERMINATE;
    end;
    SQL> /
    123669418
    899295736
    1119206239
    -832563190
    1837351612
    -804666980
    -665381754
    1733308646
    787621970
    -1865229406PL/SQL procedure successfully completed.
      

  5.   

    to enhydraboy,如果不存在表里面,java程序难道要一直运行并保存一个存有所有已生成随机数的集合?如果随机数过多,那么内存消耗严重,即使存在文件里面,对文件的读取和查找效率显然不如数据库表上的列,所以我觉得存在数据库里并且建立相应的索引比较好:)
      

  6.   

    我不是很懂,为什么不用DBMS_RANDOM?
    DBMS_RANDOM.INITIALIZE (sysdate);
    ....
    行不?
      

  7.   

    to acmly()
       我想你的意思有两种方案:
    (1) 建立一张类似序列号表,由产生序列号的代码用于判断给出唯一的序列号。
    (2) 产生序列号的代码不用考虑是否重复的问题,在生产程序中查询是否已经有该号码的存在,如果存在就再去一次,直到为新的位置。我想单用户应该没有问题,如果是多用户并发的话,应该有更多的事情需要考虑。还有如果采用serialized并发的方法,性能会怎么样呢?
      

  8.   

    可以考虑在存放 序号的这个表中 加上unique约束,
    每次取到序号后都尝试插入到这个表里面,插入失败,则重新取