gpt4 book ai didi

sql - 如何确定实际的数据库行插入顺序?

转载 作者:行者123 更新时间:2023-12-04 20:53:18 24 4
gpt4 key购买 nike

我有一个多线程进程,它将多条记录插入到一​​个表中。插入在存储过程中执行,并生成序列 INTO一个变量,该变量稍后在 INSERT 中使用.

鉴于我不做 mysequence.nextvalINSERT本身,这让我认为两个并发进程可以按一个顺序抓取一个序列,然后按相反的顺序进行插入。如果是这种情况,那么序列号将不会反射(reflect)插入的真实顺序。

我也记录了sysdateDATE我的每个插入的列,但我注意到两个记录的日期经常匹配,我需要按序列号排序以打破平局。但是考虑到之前的问题,这似乎并不能保证实际的插入顺序。

如何确定插入数据库的绝对顺序?

最佳答案

DATE 数据类型仅以秒为单位,而 TIMESTAMP 以毫秒为单位。这能解决问题吗?

根据 Oracle 的文档:

TIMESTAMP: Year, month, and day values of date, as well as hour, minute, and second values of time, where fractional_seconds_precision is the number of digits in the fractional part of the SECOND datetime field. Accepted values of fractional_seconds_precision are 0 to 9. The default is 6. The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The sizes varies from 7 to 11 bytes, depending on the precision. This datatype contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It contains fractional seconds but does not have a time zone.



date才不是:

DATE: Valid date range from January 1, 4712 BC to December 31, 9999 AD. The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is fixed at 7 bytes. This datatype contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It does not have fractional seconds or a time zone.



当然,话虽如此,我不确定为什么写记录的时间很重要,但这是一种可能会解决您的问题的方法。

关于sql - 如何确定实际的数据库行插入顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3266273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com