暂无图片
暂无图片
9
暂无图片
暂无图片
1
暂无图片

Oracle如何手动迁移sequence且防止sequence产生跳号

原创 杨金福 云和恩墨 2021-10-21
1976

在做XTTS迁移时,发现某一特定sequence未迁移至目标环境,决定在目标环境,根据源端的DDL语句重建.

但客户要求,为防止sequence产生重号或跳号,在目标环境下的sequence start with值,需要与源端连续.

1.相关视图dba_sequences,特别关注字段increment_by

select * from dba_sequences where sequence_owner = 'HR' and sequence_name = 'MDRS_31C87C$';


2.原端数据库当前会话中,如何生成nextval和读取currval

[oravis@r12 ~]$ sqlplus hr/hr

SQL*Plus: Release 11.1.0.7.0 - Production on Sat May 1 12:49:56 2010

Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

HR@VIS> select MDRS_31C87C$.nextval from dual;
210
HR@VIS> select MDRS_31C87C$.currval from dual;
210

3.生成目标端创建sequence语句

--sequence with cache

select 'create sequence ' || sequence_owner || '.' || SEQUENCE_NAME ||
' start with ' || LAST_NUMBER || ' maxvalue ' || MAX_VALUE ||
' minvalue ' || MIN_VALUE || ' increment by ' || INCREMENT_BY ||
' cache ' || CACHE_SIZE || ' ' ||
decode(CYCLE_FLAG, 'N', 'NOCYCLE', 'CYCLE') || ' ' ||
decode(ORDER_FLAG, 'N', 'NOORDER', 'ORDER') || ' ;' "-- create seq scripts"
from dba_sequences
where cache_size != 0
and sequence_owner = 'HR'
and sequence_name = 'MDRS_31C87C$';
--注:为保持sequence在目标端的值跟原端连续,last_number需要修改为:在原端环境的CURRVAL-INCREMENT_BY


-sequence without cache
select 'create sequence ' || sequence_owner || '.' || sequence_name || ' start with ' || last_number ||
' maxvalue ' || max_value || ' minvalue ' || min_value ||
' increment by ' || increment_by || ' NOCACHE ' ||
decode(cycle_flag, 'N', 'NOCYCLE', 'CYCLE') || ' ' ||
decode(order_flag, 'N', 'NOORDER', 'ORDER') || ' ;' "-- create seq scripts"
from dba_sequences
where cache_size = 0
and sequence_owner = 'BEN'
and sequence_name = 'BEN_TCS_CAT_S';
--注:为保持sequence在目标端的值跟原端连续,last_number需要修改为:在原端环境的CURRVAL-INCREMENT_BY


最后修改时间:2021-10-21 18:01:18
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

超越无限D
暂无图片
1年前
评论
暂无图片 1
发现某一特定sequence未迁移至目标环境,决定在目标环境,根据源端的DDL语句重建.
1年前
暂无图片 1
评论