如何在 SQL Server DateTime 中存储 Oracle TimeStamp 精度 6
我有一个场景,我必须将数据从 Oracle 表移动到 SQL Server 表。 Oracle 中的列是 Timestamp(6) 6 是精度。现在我无法以字符串格式发送 Oracle 数据。我直接从 Oracle 表中提取数据,因此无法在 Oracle 端对其进行格式化。我能做的是使用 VB6.Format 格式化数据,使其适合 SQL Server DateTime。我正在为 Oracle Date 到 SQL Server Datetime 执行此操作。
可以对时间戳和日期时间执行类似的操作吗?
I've a scenario where I've to move data from a Oracle Table to a SQL Server table. The column in Oracle is Timestamp(6) 6 being the precision. Now I cannot send the Oracle Data in string format. I pull the data straight from the Oracle Table, so cannot format it on oracle side. What I can do is format the data using VB6.Format to make it suitable for SQL Server DateTime. I'm doing this for Oracle Date to SQL Server Datetime.
Can something similar be done for timestamp and Datetime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您使用的 SQL Server 版本。正如 @onedaywhen 在他的评论中指出的那样,您可以使用 DATETIME,但您会失去一些精度,因为 DATETIME 只能精确到大约 3 位小数(精确度为 3.33 毫秒);但是,如果您使用的是早期版本的 SQL Server,那么您就可以得到这样的结果。
如果您运行的是 SQL Server 2008,则可以使用 DATETIME2,它精确到 100 纳秒或 7 位数字,这将处理您想要执行的操作。
如果您确实愿意,您可以使用 DECIMAL 列来修改一些内容来表示日期/时间。您可以将列设置为 DECIMAL(20, 6) 并将其格式设置为
其中
实现留给读者作为练习。
(警告:如果您选择使用类似的格式,请注意,同样的日期/时间格式在《死灵之书》的原始版本中被用作计时的基础,并且有传言直接导致了作者 Abdul Alhazred,被称为“疯狂的阿拉伯人”:-)
Cthulhu fthagn。
That depends on the version of SQL server you're using. As @onedaywhen pointed out in his comment you could use DATETIME, but you'll lose some precision as DATETIME is only accurate to around 3 decimal digits (3.33 millisecond accuracy); however, if you're on an earlier version of SQL Server that's what you've got.
If you're running SQL Server 2008 you can use DATETIME2, which is accurate to 100 nanoseconds or 7 digits, which would handle what you're trying to do.
If you really wanted to you could hack something up to represent dates/times using DECIMAL columns. You might make the columns DECIMAL(20, 6) and format them as
where
Implementation is left as an exercise to the reader.
(CAVEAT: should you choose to use something like this, be aware that this same date/time format was used as the basis of timekeeping in the original version of the Necronomicon, and is rumored to have directly resulted in the author, Abdul Alhazred, being known as "the mad Arab". :-)
Cthulhu fthagn.