Oracle的timestamp字段更新实验 结论:只有逐条更新才能保证timestamp字段有差别,批量更新只会得到一致的时间,此操作无关时间精度.
有这么一张表:
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字段有差别,批量更新只会得到一致的时间,此操作无关时间精度.的更多相关文章
- 转://批量更新sequence的存储
前言: ORACLE的序列(SEQUENCE)A SCHEMA OBJECT THAT GENERATES A SERIAL LIST OF UNIQUE NUMBERS FOR TABLE COLU ...
- Mybatis 批量更新遇到的小问题
小问题 记一个开发过程中因为小细节的遗漏而引发的 "莫名其妙",公司中有个2B(to B)供应链项目,持久层用的是 JPA,这里我就不吐槽 JPA 了,这种 SQL 嵌入在代码里的 ...
- mysql语句:批量更新多条记录的不同值[转]
mysql语句:批量更新多条记录的不同值 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 帮助 1 UPDATE mytable SET myfield = 'value' WHERE ...
- mysql 批量更新与批量更新多条记录的不同值实现方法
批量更新 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 代码如下: UPDATE mytable SET myfield = 'value' WHERE other_field = ...
- mysql 批量更新
bs_user 表,我们叫他 bu表, 字段user_id,len_id, think_wellUser 表,我们简称为tw表,中的user_id ,len_id 其中tw表的user_id 是bu表 ...
- mysql语句:批量更新多条记录的不同值
mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 1 UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_va ...
- mysql 批量更新与批量更新多条记录的不同值实现方法
作者: 字体:[增加 减小] 类型:转载 时间:2013-10-02 我要评论 在mysql中批量更新我们可能使用update,replace into来操作,下面小编来给各位同学详细介绍mysql ...
- mysql进阶(十四) 批量更新与批量更新多条记录的不同值实现方法
mysql 批量更新与批量更新多条记录的不同值实现方法 在mysql中批量更新我们可能使用update,replace into来操作,下面详细介绍mysql批量更新与性能. 批量更新 mysql更新 ...
- 【转】【MySql】Update批量更新与批量更新多条记录的不同值实现方法
批量更新 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: UPDATE mytable SET myfield = 'value' WHERE other_field = 'other ...
随机推荐
- 2020-07-21:简述redis主从同步的过程。
福哥答案2020-07-21: 1.从服务发送一个sync同步命令给主服务要求全量同步.2.主服务接收到从服务的sync同步命令时,会fork一个子进程后台执行bgsave命令(非阻塞)快照保存,生成 ...
- C#LeetCode刷题之#682-棒球比赛(Baseball Game)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4028 访问. 你现在是棒球比赛记录员. 给定一个字符串列表,每个 ...
- 实型(浮点型):float、double
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<stdlib. ...
- storcli 命令(更新Ing)
help [root@centos7]# storcli -h Storage Command Line Tool Ver 007.0606.0000.0000 Mar , (c)Copyright ...
- 数据 恢复----判断Raid盘序及校验方向
重组Raid(如何判断校验方向及盘序) 1. 常规左异结构[backward parity(反向奇偶校验--(静态))] 校验块:校验块从最后一块物理盘开始写起,然后依次往前面的盘中写入,当写到第一块 ...
- put数据到topic
基于python3.6 # -*-coding:utf-8 *- __author__ = 'lc_yy' from pykafka import KafkaClient import logging ...
- python基础 - 切片
今日学习内容 切片 取一个list或者tuple的部分数据是常见的操作 a = [1,2,3] 比如取第一个数我们可以用a[0]的方式,如果我们想取第一个和第二个就有点困难了,a[0-1]或者a[0] ...
- R 安装包的方法
install.packages(packageName) install.packages(path_to_file, repos = NULL, type="source") ...
- 谈谈javascript的基本规范~~~~
1.不要在同一行声明多个变量. 2.请使用===或==来比较true或false或者数值 3.使用对象字面量代替new Array这种形式 4.不要使用全局函数 5.switch语句必须带有defau ...
- chained get value from nested json
static getValueByKey(o, p, defaultValue = false) { return p.split('.').reduce((r, k) => { if (typ ...