zoukankan      html  css  js  c++  java
  • oracle:序列

    查看用户已建的序列:select sequence_name from user_sequences;--SEQ_RULE_OPER_ROLE
    select max(oper_role_id) from crm_pub.rule_oper_role;-- 看当前的最大序列号是多少.
    select * from crm_pub.rule_oper_role order by oper_role_id desc;  --倒序
    创建序列公式:
    CREATE SEQUENCE seqTest
    INCREMENT BY 1 -- 每次加几个
    START WITH 1 -- 从1开始计数
    NOMAXvalue -- 不设置最大值
    NOCYCLE -- 一直累加,不循环
    CACHE 10; --设置缓存cache个序列,如果系统down掉了或者其它情况将会导致序列不连续,也可以设置为---NOCACHE
    create sequence seq_rule_oper_role increment by 1 start with 100000187614 nomaxvalue nocycle cache 10;
    select 序列名.currval from dual;  //获取序列的当前值,这个值是可变的。
    创建Sequence后直接查询它的当前值(CURRVAL)会出错,要先调用Sequence对象.NEXTVAL,才能查询当前值。
    select seq_rule_oper_role.nextval from dual;--100000187614
    select seq_rule_oper_role.currval from dual;
    修改序列初始值的两种方法:
    一、先删除序列,然后重新创建。这个方法比较方便。
    二、通过Increment By来实现修改初始值。
    例如:若序列名称是seqTest,初始值是13,而现在要设置初始值为1020,Increment By值为:1007(1020-13)
    1.执行:Alter Sequence seqTest Increment By 1007;
    2.执行:Select seqTest.NextVal From Dual;
    3.执行:Alter Sequence seqTest Increment By 1; 
     
    使用:seq_rule_oper_role.Nextval
    insert into crm_pub.rule_oper_role
      (oper_role_id, oper_id, role_id, create_date, create_operator_id)
      select (seq_rule_oper_role.Nextval), oper_no, 'SH001', sysdate, '1'
        from crm_pub.logins_oper_temp b;
  • 相关阅读:
    费用流
    平面最近点对
    纸牌均分问题
    cdq分治模板
    费解的开关
    斐波那契和排列组合性质
    主席树
    Springboot使用EasyExcel(仅限自己收藏)
    vue项目中h5移动端中通过flex布局实现首尾固定,中间滚动(借鉴)
    vue路由参数的获取、添加和替换
  • 原文地址:https://www.cnblogs.com/phpli/p/7885965.html
Copyright © 2011-2022 走看看