PostgreSQL/Oracle Table
通常我們在建立 PostgreSQL/Oracle 資料庫的時候, 如果要使用 MySQL/MS-SQL identity 雷同的功能, 就是要採用 Sequence 來建立, 而為了每一個 Table 都有獨立的序號產生器, 我們會建立個別的 sequence.
例如 (PostgreSQL sample):
CREATE SEQUENCE "student_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1;
create table student (
id bigint PRIMARY KEY DEFAULT NEXTVAL('student_seq'),
name character varying(50),
studentno character varying(50)
)
當我們使用基本的 SQL command 就是
Insert into student ( name, studentno ) values ( 'jini', '890099' )
進行 Insert 的動作, 他自然會幫我取得 nextval of student_seq 進行 Insert.
那麼, 在 Hibernate annotation 標準的作法, 就是
@Entity
@SequenceGeneratorr(name = "TheSEQ", allocationSize = 1, initialValue = 0, sequenceName = "student_seq")
public class Student implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE
, generator = "TheSEQ")
private Long id;
// other attributes, getters and setters
}
這樣, 我每一個 @Id 都得花時間寫指定的 sequence name,
雖然沒有什麼不好, 但是我們可以利用 [tablename]_seq 的原則定義 seq, 就應該可以透過 Dialect 來決定我的 IdGenerator 的方式
所以我希望未來的程式碼只有以下所列, 利用 AUTO 而非 SEQUENCE generated type.
@Entity
public class Student implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private
相关文档:
oracle表空间操作详解
1
2
3作者: 来源: 更新日期:2006-01-04
5
6
7建立表空间
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
一、ORACLE的启动和关闭
1、在单机环境下要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下
su - oracle
a、启动ORACLE系统
oracle>svrmgrl
SVRMGR>connect internal
SVRMGR>startup
SVRMGR>quit
b、关闭ORACLE系统
oracle>svrmgrl
SVRMGR>connect internal
SVRMGR>shutdow ......
一、ORACLE的启动和关闭
1、在单机环境下要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下
su - oracle
a、启动ORACLE系统
oracle>svrmgrl
SVRMGR>connect internal
SVRMGR>startup
SVRMGR>quit
b、关闭ORACLE系统
oracle>svrmgrl
SVRMGR>connect internal
SVRMGR>shutdow ......
查询时可以指定使用索引的写法。
SELECT /*+ index(TB_ALIAS IX_G_COST3) */
TB_ALIAS.*
from g_Cost TB_ALIAS
WHERE Item_Two = 0
AND Flight_Date >= To_Date('20061201', 'YYYYMMDD')
AND Flight_D ......
如果是中文字符集:
[TEST@ora10gr1#2009-11-25/08:39:38]
SQL>create table t1(t timestamp);
Table created.
[TEST@ora10gr1#2009-11-25/08:39:56]
SQL>insert into t1 values(to_timestamp('21NOV09 10:04:12.032','DDMONYY HH24:MI:SS.FF'));
* ERROR at li ......