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有关问题的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [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 ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  10. 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 ...

随机推荐

  1. JS=和==和===的区别

    1. = : 赋值运算,赋值使用2.== :比较运算,仅比较自动转换后的值是否相等,忽略 变量类型,如:'1' == 1 //true 3.=== : 比较运算,比较值和变量类型是否相等,如:'1' ...

  2. go实现生产者消费者

    package main import ( "fmt" "math/rand" ) func main() { ch := make(chan int) don ...

  3. JAVA 时间的使用

    今天老师又没有讲新课,不过讲了练习题,扩展了一下我们的思维. 今天就讲一下如何获取时间吧. 代码: import java.util.* public class Test{ public stati ...

  4. spring boot图片上传至远程服务器并返回新的图片路径

    界面上传图片时考虑到可能会有用户的图片名称一致,使用UUID来对图片名称进行重新生成. //UUIDUtils public class UUIDUtils { public static Strin ...

  5. WebService学习之旅(一)使用JAX-WS发布WebService

    JAX-WS全称Java™ API for XML Web Services,是随着JDK1.6及其后续版本发布的方便Java程序员开发WebService应用的一组API,通常简称为JWS,目前版本 ...

  6. Web开发者应掌握的12个Firebug技巧

    来源: 廖煜嵘 相信很多从事Web开发工作的开发者都听说和使用过Firebug,但可能大部分人还不知道,其实它是一个在网页设计方面功能相当强大的编辑器,它 可以对HTML.DOM.CSS.HTTP和J ...

  7. HDU 4003 Find Metal Mineral (树形DP,经典)

    题意:给定一棵树图,n个节点,有边权,要派k<11个机器人从节点s出发,遍历所有的点,每当1只机器人经过1条边时就会花费该边的边权,边是可重复走的.问遍历完所有点的最小花费? 思路: 非常经典, ...

  8. 51nod 1283 最小周长

    一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值.例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小,为 ...

  9. ubuntu 14.04 安装mysql,并配置远程连接和中文乱码

    1. 安装MySQL的jar root@computer-PowerEdge-T30:~# sudo apt-get install mysql-server mysql-client在本次安装中,根 ...

  10. SQLite C/C++ 教程

    目录 1安装 2 C/C++ Interface APIs 3连接到数据库 4创建表 5插入操作 6更新操作 7删除操作 安装 在我们开始使用SQLite在C / C++程序,我们需要确保SQLite ...