Oracle之select SEQ_YX.nextval from dual是什么意思?


dual : 是oracle的虚拟表,不是真实存在的.
SEQ_YX : 这个是开发人员自己起的一个"序列"的名字,序列一般用于生成id号.
SEQ_YX.nextval 就是取序列的下一个值

举个例子来说
序列当前的值是100,执行一下上面的语句就会取到101,再执行一下就会取到102,一直累加下去

 

在创建sql语句中也加上了创建序列的语句:

declare 
  ssql  varchar2(4000);
  tCount number(2);
  iCount number(2);
  sCount number(2);

begin
  tCount := 0;
  select count(*) into tCount from user_all_tables t where upper(t.table_name) = upper('ppos_notice_relateinfo');
  if tCount = 0 then
      ssql := 'create table ppos_notice_relateinfo
(
    ID integer NOT NULL ,
    USER_ID varchar2(64) NOT NULL ,
  NOTICE_ID varchar2(64) NOT NULL ,
  ISREAD_FLAG varchar2(1) NOT NULL ,         
  creator varchar2(16),
  creater_time TIMESTAMP ,
  operator varchar2(16) ,
  operate_time TIMESTAMP,
    constraint PK_ppos_notice_relateinfo primary key (id) using index tablespace HS_SYSTEM_IDX ) tablespace HS_SYSTEM_DATA';
  execute immediate ssql;
  end if;
   select count(1) into iCount from user_indexes t where t.index_name= upper('uk_ppos_notice_relateinfo_idxl'); 
  if sCount = 0 then
     execute immediate 'create unique index uk_ppos_notice_relateinfo_idxl on ppos_notice_relateinfo (NOTICE_ID,USER_ID) tablespace HS_SYSTEM_IDX';
  end if;
   select count(*) into sCount from user_sequences us where us.sequence_name = upper('SEQ_ppos_notice_relateinfo');
  if sCount = 0 then
     execute immediate 'create sequence SEQ_ppos_notice_relateinfo minvalue 1 maxvalue 999999999 start with 1 increment by 1';
  end if;
end;
/

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM