如何在表格中插入时指定增量编号 [英] How to assign Incremental number while insert in table

查看:117
本文介绍了如何在表格中插入时指定增量编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将特定日期的记录插入到另一个表格。

同时我想将增量号码插入到另一张相同的表格中wrt记录

如下所示

 TableA 
----------
ColA ColB ColDate
101 a 2014年7月21日
102 b 21-Jul-2014
103 c 2014年7月22日





插入后

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

解决方案

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;


这篇关于如何在表格中插入时指定增量编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆