有这么一张表:

create table hy_testtime(
id number(6,0) not null primary key,
name nvarchar2(20) not null,
utime timestamp(6)
)

如果这样给它充值:

insert into hy_testtime
select rownum,
dbms_random.string('*',dbms_random.value(1,20)),
sysdate
from dual
connect by level<100 commit;

那么充值完毕后,其utime字段都会是一样的.(SQL:select to_char(utime,'yyyy-mm-dd hh24:mi:ss.ff6') from hy_testtime)

然后,用传统的反连接找utime最新的记录,会把所有99条结果都找出来.

select count(*)
from hy_testtime a
where not exists (select null from hy_testtime b where b.utime>a.utime)

这就不是我们期待的一条记录了.

让我们换一张表:

create table hy_testtime2(
id number(6,0) not null primary key,
name nvarchar2(20) not null,
utime timestamp(6)
)

这样给它充值:

insert into hy_testtime2
select rownum,
dbms_random.string('*',dbms_random.value(1,20)),
systimestamp
from dual
connect by level<100

这回换用了systimestamp,但时间还是一样的.

这当然还不是我们想要的.于是我们用以下更新语句去更新:

update hy_testtime2 set utime=systimestamp where id<10;
commit;

再查一下:

select to_char(utime,'yyyy-mm-dd hh24:mi:ss.ff6') from hy_testtime2 where id<10

看来,只要批量更新,就会造成utime是一样的结果.

但我们去一条条更新,如下所示:

update hy_testtime2 set utime=systimestamp where id=11;

update hy_testtime2 set utime=systimestamp where id=12;

然后再查查:

select to_char(utime,'yyyy-mm-dd hh24:mi:ss.ff6') from hy_testtime2 where id in(11,12)

这就可以发现更新时间是不一致了.

然后再查一下utime最新记录有几条:

select count(*)
from hy_testtime2 a
where not exists (select null from hy_testtime2 b where b.utime>a.utime)

再看看是否是id=12的那条:

select a.*
from hy_testtime2 a
where not exists (select null from hy_testtime2 b where b.utime>a.utime)

果然是.

结论: 如果是批量更新timestamp字段,那更新上去的值必然一致,无论是用sysdate还是systimestamp都是一样.

如果要拉开时间,必须一条条去更新,如果不是取Oracle的systimestamp,那么使用Java中的Timsstamp类保证精度也是一样效果.

当然,在并行环境里,utime字段还有可能会重复! 这时可行方案是发现重复再取一次时间,再设置回去. 流程是:更新utime,检查utime有无重复,发现重复则再次更新utime.

参考资料:http://www.itpub.net/thread-1931266-4-1.html

--2020-02-25--

Oracle的timestamp字段更新实验 结论:只有逐条更新才能保证timestamp字段有差别,批量更新只会得到一致的时间,此操作无关时间精度.的更多相关文章

  1. 转://批量更新sequence的存储

    前言: ORACLE的序列(SEQUENCE)A SCHEMA OBJECT THAT GENERATES A SERIAL LIST OF UNIQUE NUMBERS FOR TABLE COLU ...

  2. Mybatis 批量更新遇到的小问题

    小问题 记一个开发过程中因为小细节的遗漏而引发的 "莫名其妙",公司中有个2B(to B)供应链项目,持久层用的是 JPA,这里我就不吐槽 JPA 了,这种 SQL 嵌入在代码里的 ...

  3. mysql语句:批量更新多条记录的不同值[转]

    mysql语句:批量更新多条记录的不同值 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 帮助 1 UPDATE mytable SET myfield = 'value' WHERE ...

  4. mysql 批量更新与批量更新多条记录的不同值实现方法

    批量更新 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 代码如下: UPDATE mytable SET myfield = 'value' WHERE other_field = ...

  5. mysql 批量更新

    bs_user 表,我们叫他 bu表, 字段user_id,len_id, think_wellUser 表,我们简称为tw表,中的user_id ,len_id 其中tw表的user_id 是bu表 ...

  6. mysql语句:批量更新多条记录的不同值

    mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 1 UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_va ...

  7. mysql 批量更新与批量更新多条记录的不同值实现方法

    作者: 字体:[增加 减小] 类型:转载 时间:2013-10-02 我要评论 在mysql中批量更新我们可能使用update,replace into来操作,下面小编来给各位同学详细介绍mysql ...

  8. mysql进阶(十四) 批量更新与批量更新多条记录的不同值实现方法

    mysql 批量更新与批量更新多条记录的不同值实现方法 在mysql中批量更新我们可能使用update,replace into来操作,下面详细介绍mysql批量更新与性能. 批量更新 mysql更新 ...

  9. 【转】【MySql】Update批量更新与批量更新多条记录的不同值实现方法

    批量更新 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: UPDATE mytable SET myfield = 'value' WHERE other_field = 'other ...

随机推荐

  1. one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3, 1280, 28, 28]], which is output 0 of LeakyReluBackward1, is at version 2;

    RuntimeError: one of the variables needed for gradient computation has been modified by an inplace o ...

  2. C#LeetCode刷题之#860-柠檬水找零(Lemonade Change)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4036 访问. 在柠檬水摊上,每一杯柠檬水的售价为 5 美元. 顾 ...

  3. vue keep-alive 不生效和多级(三级以上)缓存失败

    vue keep-alive https://cn.vuejs.org/v2/api/#keep-alive keep-alive 不生效的可能原因 如果安装官方的写法,已经正常完成keep-aliv ...

  4. xshell乱码解决办法

    https://jingyan.baidu.com/article/7908e85c758a58af481ad2ae.html

  5. GUAVA-cache实现

    GUAVA  Cache Guava Cache与ConcurrentMap很相似基于分段锁及线程安全,但也不完全一样.最基本的区别是ConcurrentMap会一直保存所有添加的元素,直到显式地移除 ...

  6. 通过C#实现OPC-UA服务端(二)

    前言 通过我前面的一篇文件,我们已经能够搭建一个OPC-UA服务端了,并且也拥有了一些基础功能.这一次咱们就来了解一下OPC-UA的服务注册与发现,如果对服务注册与发现这个概念不理解的朋友,可以先百度 ...

  7. windows下RocketMQ的安装部署

    一.预备环境 1.系统 Windows 2. 环境 JDK1.8.Maven.Git 二. RocketMQ部署 1.下载 1.1地址:http://rocketmq.apache.org/relea ...

  8. JavaScript学习系列博客_18_JavaScript中的匿名函数

    匿名函数 - 用函数声明的方式创建一个函数时,不加函数名称. function sum(){ console.log("我是函数sum")} - 不加名称,这样写浏览器是会报错的. ...

  9. Pytools1.0.0发布啦!

    大家赶紧来看看,特别好用的. 文档: This is pytools modulethe module is use MIT license MIT License Copyright (c) 202 ...

  10. 第六篇scrum冲刺

    一. 站立式会议 1.会议照片 2. 项目进展 团队成员 昨日完成任务 今日计划任务 吴茂平  新消息提醒功能设计 实现开发新消息提醒功能 陈忠明 歌曲批量下载压缩包 歌手收藏功能 吴尚谦  设计下载 ...