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