创建序列如何从指定的表中选取最大值开始
比如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
------解决方案--------------------
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;
/