oracle沒有設定主鍵auto increment 的功能,需要自己白那些序列和觸發器實現主鍵自動遞增。
示例:建立表menu:
create table menu( menuid number(10) not null primary key,
name varchar2(40) not null,
id_parent number(10) not null,
url varchar2(300) null);
建立序列menu_autoinc_seq:
create sequence menu_autoinc_seq
minvalue 1
maxvalue 99999999
start with 1
increment by 1
nocycle
nocache
order;
建立觸發器menu_autoinc_tg:
create or replace trigger menu_autoinc_tg
before insert on menu for each row
begin
select menu_autoinc_seq.nextval into :new.menuid from dual;
end menu_autoinc_tg;
其中end語句可以寫成end;
在command window進行建立資料庫物件的時候,如果使用到了多行語句,可在結束後另起一行輸入/
測試:
insert into menu values('','個人事務',0,'indi.php');
insert into menu values('','公共事務',0,'public.php');
sql 設定主鍵 聯合主鍵
alter table yourtable add constaintname primary key columnname constaintname 資料型別 yourtable 表名 columnname 列名 or create table yourtable column1 int pri...
jpa設定自增主鍵 jpa如何設定主鍵自動增長
這個策略我已經試過了,auto和identity了,還是出錯。我想問hibernate對映檔案設定主鍵的generation native到了jpa在 設定呢?generatedvalue strategy generationtype.auto idpublic integer getid ret...
Hibernate主鍵的設定
1 適用於mysql,mssql 自動增長identity oracle不支援自動增長,但是支援序列,所以,這個方法一般用於mysql,mssql generator class identity generator 要想在hibernate中配置oracle的主鍵,需要用到序列 2 序列seque...