比如client表,有列ID,我想创建一个sequence:seq_client, start with client中的Max(ID)。如何实现? 
谢谢。老外写的我没测试通过呢?
http://forums.devshed.com/oracle-development-96/create-sequence-using-subselect-value-from-select-542288.html

解决方案 »

  1.   

    创建一个从大到小的序列不可以吗?
    create sequence seq_reverse
    start with 1000
    increment by -1
    maxvalue 100
    minvalue 1
    nocycle
    order
      

  2.   

    总有一天有可能会跟Max(ID)重复的。还是避免的好。呵呵。
      

  3.   

    没写出来…… 
    我pl/sql写,他不让我在begin end中用create……
      

  4.   

    CREATE sequence customer_id start with (select max(customer_id) from customer) increment by 1;
    没有这种语法。DECLARE
      v_max_id NUMBER;
    BEGIN
      --取出最大值
      SELECT MAX(customer_id) INTO v_max_id FROM customer;
      --动态创建seq
      EXECUTE IMMEDIATE ' CREATE sequence customer_id
       START WITH ' || v_max_id || ' increment BY 1';
    END;
    /
      

  5.   


    -- 你分两部走撒:
    -- *(01) 用查询语句查出当前 client表中的id字段的最大值:
    select maxi(id) from client;-- 用上面查询得到的值+1作为你要创建的序列的起始值!