且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在表格中插入时指定增量编号

更新时间:2022-12-12 17:08:57

Oracle建议在这里实现这一目标的***途径 http://www.oracle-base.com/articles/misc/autonumber-and- identity.php [ ^ ]

1。在表B中插入值之前,计算表B中的最大数量。



从表B中选择最大值(RecordNumber)+1 [RecNumber]



2.在tableB的插入查询中使用最大数字和其他详细信息。


这将获取当前的自动增量值。



SELECT IDENT_CURRENT('table_name');



下一个自动递增值。



SELECT IDENT_CURRENT('table_name')+ 1;


I want to insert records for particular day to another table.
At the same time i want to insert incremental number to another same table w.r.t record
like below

TableA
----------
ColA	ColB	ColDate
101	a	21-Jul-2014
102	b	21-Jul-2014
103	c	22-Jul-2014



After insert

TableB
----------
ColA	RecordNumber	ColB	ColDate
101	1		a	21-Jul-2014
102	2		b	21-Jul-2014
103	3		c	22-Jul-2014

Oracle advise on the best way to achieve this here http://www.oracle-base.com/articles/misc/autonumber-and-identity.php[^]


1. Before inserting the values in table B, calculate the max number from tableB.

Select Max(RecordNumber)+1 [RecNumber] from tableB

2. In the insert query for tableB use the max number with the other details.


This will fetch the present auto-increment value.

SELECT IDENT_CURRENT('table_name');

Next auto-increment value.

SELECT IDENT_CURRENT('table_name')+1;