sequence有关问题
sequence问题
比如主键是 1,3,5,7,9,11 中间跳号了。。。
用什么方法可以把主键重新排列为 1,2,3,4,5
------解决方案--------------------
update tablename set id=rownum
通过下面的方法重置你得序列修改那个start with值
SQL> create sequence seq_1 increment by 1 start with 1 maxvalue 999999999;
序列已创建。
SQL> create or replace procedure seq_reset(v_seqname varchar2) as
2 n number(10);
3 tsql varchar2(100);
4 begin
5 execute immediate 'select '||v_seqname||'.nextval from dual' into n;
6 n:=-(n-1);
7 tsql:='alter sequence '||v_seqname||' increment by '|| n;--让序列一次递增-N,实现归0
8 execute immediate tsql;
9 execute immediate 'select '||v_seqname||'.nextval from dual' into n;
10 tsql:='alter sequence '||v_seqname||' increment by 1';
11 execute immediate tsql;
12 end seq_reset;
13 /
过程已创建。
SQL> select seq_1.nextval from dual;
NEXTVAL
---------
2
SQL> /
NEXTVAL
---------
3
SQL> /
NEXTVAL
---------
4
SQL> /
NEXTVAL
---------
5
SQL> exec seq_reset('seq_1');
PL/SQL 过程已成功完成。
SQL> select seq_1.currval from dual;
CURRVAL
---------
1
SQL>
------解决方案--------------------
第一种方法:
这种方法可以实现你的要求,但要分两步做:
(1)创建一个序列:
create sequence minus_value
start with 1
minvalue 1
increment by 1;
(2)更新数据库列
update yourtable set colnum=minus_value.nextval;
如果是一个刚刚新创建的序列,则执行上面的更新语句后,可以保证主键顺序是从1开始的.
如果你所用的序列是一个已经被用过的,则还要执行一个更新语句,
update yourtable set colnum=colnum - <value>;
这个value就是序列的起始值与1的差值.
第二种方法:
可以用ROWNUM与主键值之间的差值实现
sequence有关问题的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- Leetcode 60. Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- IDEA Maven无法添加依赖到项目中
IDEA--------->File-------->Setting------------>Maven 勾上即可,OK啦! 完美解决了
- jQuery测试及解析
解析:下标从0开始 解析:最大119 解析:鼠标移过mouseover 解析: var 变量值=变量名
- C# 枚举类型的描述信息获取
新建一个控制台方法,写好自己的枚举类型: 如图: 在里面添加获取描述的方法: 具体源码: 链接:http://pan.baidu.com/s/1nv4rGkp 密码:byz8
- js AES对称加密 16进制和base64格式
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Linux KDE 设置显示桌面的快捷键 win+d
原文链接:http://blog.sina.com.cn/s/blog_4b91893c0100sxxg.html 到KDE下以后发现显示桌面的快捷键被用来显示平铺窗口,在Win下的时候一直用这个快捷 ...
- debian中sudo无法使用问题
原文链接:http://sharadchhetri.com/2013/08/07/sudo-command-not-found-debian-7/ To solve this issue instal ...
- IP-XACT IP IEEE交换格式
1 What is IP-XACT? IP-XACT is an XML format that defines and describes electronic components a ...
- 验证 .NET 4.6 的 SIMD 硬件加速支持的重要性
SIMD 的意思是 Single Instruction Multiple Data.顾名思义,一个指令可以处理多个数据. .NET Framework 4.6 推出的 Nuget 程序包 Syste ...
- 安卓统一推送联盟融云成唯一IM云服务企业
10月16日,安卓统一推送联盟在北京正式成立,来自中国信息通信研究院,华为.小米.OPPO等手机厂商,BAT等互联网巨头公司等75家机构及企业代表参加了联盟成立大会,融云也受邀参会并成为首批成员单位中 ...
- UVA10917 A walk trough the Forest (最短路,dp)
求出家到其他点的最短路径,题目的条件变成了u->v不是回头路等价于d[u]>d[v]. 然后根据这个条件建DAG图,跑dp统计方案数,dp[u] = sum(dp[v]). #includ ...