Oracle Sequence

-- Create sequence 
create sequence GB_SEQ
minvalue 1
maxvalue 999999999999999999999999999
start with 41
increment by 1
cache 20;

--Look Sequence
select gb_seq.nextval from dual;

--Use Sequence
insert into user(id, name) values(gb_seq.nextval, 'your name');

create sequence seq_id   --创建序列号
increment by 1
start with 1
nomaxvalue;


create sequence seq_id  
increment by 1   
start with 1   
nomaxvalue
cache 10;

select seq_id.nextval from dual;

 create table users
 (cardid number not null primary key,
 username varchar2(10)
  );
  
  create table account
  (countid number not null primary key,
  cardid number not null,
  score number,
  constraint fk_users_account foreign key(cardid) references users(cardid)
  );
  
insert into users values(16,'张三');
insert into users values(23,'李四');
insert into users values(25,'王五');
insert into users values(29,'刘六');
insert into users values(30,'杨七');

insert into account values(seq_id.nextval,16,34.50);
insert into account values(seq_id.nextval,25,300.00);
insert into account values(seq_id.nextval,29,1.50);

insert into account
  select seq_id.nextval, users.cardid,2 from users,account
  where users.cardid=account.cardid(+) and account.countid is null;

你可能感兴趣的:(oracle,sql,cache)