syphoninject是什么:oracle9i中,插入数据时,有一项是需要数据库自动递增生成的整型值,应该如何设置?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/08 10:58:21

自动可能比较困难,可以考虑使用sequences:
CREATE SEQUENCE supplier_seq
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20;

This would create a sequence object called supplier_seq. The first sequence number that it would use is 1 and each subsequent number would increment by 1 (ie: 2,3,4,...}. It will cache up to 20 values for performance.

Now that youve created a sequence object to simulate an autonumber field, well cover how to retrieve a value from this sequence object. To retrieve the next value in the sequence order, you need to use nextval.

For example:

supplier_seq.nextval

This would retrieve the next value from supplier_seq. The nextval statement needs to be used in an SQL statement. For example:

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(supplier_seq.nextval, Kraft Foods);