欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Oracle系列:(24)序列

什么是序列【Sequence】

我們提供的服務(wù)有:成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、銀海ssl等。為近1000家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的銀海網(wǎng)站制作公司

(1)類(lèi)似于MySQL中的auto_increment自動(dòng)增長(zhǎng)機(jī)制,但Oracle中無(wú)auto_increment機(jī)制

(2)是oracle提供的一個(gè)產(chǎn)生唯一數(shù)值型值的機(jī)制

(3)通常用于表的主健值

(4)序列只能保證唯一,不能保證連續(xù)

     聲明:oracle中,只有rownum永遠(yuǎn)保持從1開(kāi)始,且繼續(xù)

(5)序列值,可放于內(nèi)存,取之較快

 

題問(wèn):為什么oracle不直接用rownum做主健呢?

rownum=1這條記錄不能永遠(yuǎn)唯一表示SMITH這個(gè)用戶

但主鍵=1確可以永遠(yuǎn)唯一表示SMITH這個(gè)用戶

主鍵的目的就是為了唯一地標(biāo)識(shí)一條記錄,而rownum無(wú)法實(shí)現(xiàn)唯一標(biāo)識(shí)某一條記錄。

為什么要用序列

(1)以前我們?yōu)橹鹘≡O(shè)置值,需要人工設(shè)置值,容易出錯(cuò)

(2)以前每張表的主健值,是獨(dú)立的,不能共享

為emp表的empno字段,創(chuàng)建序列emp_empno_seq,

create sequence 序列名
create sequence emp_empno_seq;

刪除序列emp_empno_seq,drop sequence 序列名

drop sequence emp_empno_seq;

查詢emp_empno_seq序列的當(dāng)前值currval和下一個(gè)值nextval,第一次使用序列時(shí),必須選用:序列名.nextval

select emp_empno_seq.nextval from dual;
select emp_empno_seq.currval from dual;

Oracle系列:(24)序列

使用序列,向emp表插入記錄,empno字段使用序列值

insert into emp(empno) values(emp_empno_seq.nextval);
insert into emp(empno) values(emp_empno_seq.nextval);
insert into emp(empno) values(emp_empno_seq.nextval);

Oracle系列:(24)序列

修改emp_empno_seq序列的increment by屬性為20,默認(rèn)start with是1,alter sequence 序列名

alter sequence emp_empno_seq
increment by 20;

Oracle系列:(24)序列

修改修改emp_empno_seq序列的的increment by屬性為5

alter sequence emp_empno_seq
increment by 5;

修改emp_empno_seq序列的start with屬性,行嗎

alter sequence emp_empno_seq
start with 100;

不行,會(huì)報(bào)錯(cuò)

Oracle系列:(24)序列

但是可以在創(chuàng)建序列的時(shí)候 ,指定起始值和增長(zhǎng)值

Oracle系列:(24)序列

有了序列后,還能為主健手工設(shè)置值嗎?

insert into emp(empno) values(9999);
insert into emp(empno) values(7900);

可以

Oracle系列:(24)序列

(講課內(nèi)容)

刪除表,會(huì)影響序列嗎?

你無(wú)法做insert操作

刪除序列,會(huì)影響表嗎?

表真正亡,序列亡

【存疑:我做了試驗(yàn),徹底刪除emp表之后,還能繼續(xù)使用emp_empno_seq的nextval和currval】

在hibernate中,如果是訪問(wèn)oracle數(shù)據(jù)庫(kù)

(1)是否需要底層數(shù)據(jù)庫(kù)支持

identity需要底層數(shù)據(jù)庫(kù)支持auto_increment。在MySQL數(shù)據(jù)庫(kù)中,需要設(shè)置表的主鍵字段為自增長(zhǎng)。

而increment和uuid不需要底層數(shù)據(jù)庫(kù)支持、不需要設(shè)置主鍵字段為自增長(zhǎng)。

(2)是否支持多線程并發(fā)操作?

increment只能單線程訪問(wèn),多線程不行。

identity和uuid都支持并發(fā)操作。

(3)適用場(chǎng)景

如果只使用(專用)oracle數(shù)據(jù)庫(kù),可以使用sequence,Hibernate會(huì)自動(dòng)在Oracle數(shù)據(jù)庫(kù)中創(chuàng)建一個(gè)序列。

如果不確定使用oracle、mysql、sqlserver,可以使用native,它是一個(gè)通用的變量。一般都會(huì)使用native。

Hibernate幫助文檔

Various additional generators

All generators implement the interface org.hibernate.id.IdentifierGenerator. This is a very simple interface. Some applications can choose to provide their own specialized implementations, however, Hibernate provides a range of built-in implementations. The shortcut names for the built-in generators are as follows:

  • increment

    generates identifiers of type longshort or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster.

  • identity

    supports identity columns in DB2, MySQL, MS SQLServer, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.

  • sequence

    uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned identifier is of type long, short or int

  • uuid

    Generates a 128-bit UUID based on a custom algorithm. The value generated is represented as a string of 32 hexidecimal digits. Users can also configure it to use a separator (config parameter "separator") which separates the hexidecimal digits into 8{sep}8{sep}4{sep}8{sep}4. 

  • uuid2

    Generates a IETF RFC 4122 compliant (variant 2) 128-bit UUID. The exact "version" (the RFC term) generated depends on the pluggable "generation strategy" used. Capable of generating values as java.util.UUIDjava.lang.String or as a byte array of length 16 (byte[16]). The "generation strategy" is defined by the interface org.hibernate.id.UUIDGenerationStrategy.

  • guid

    uses a database-generated GUID string on MS SQL Server and MySQL.

  • native

    selects identity,sequence or hilo depending upon the capabilities of the underlying database.

  • assigned

    lets the application assign an identifier to the object before save() is called. This is the default strategy if no <generator> element is specified.

  • foreign

    uses the identifier of another associated object. It is usually used in conjunction with a <one-to-one> primary key  association.

本文名稱:Oracle系列:(24)序列
網(wǎng)站網(wǎng)址:http://aaarwkj.com/article40/iioeho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開(kāi)發(fā)、響應(yīng)式網(wǎng)站、網(wǎng)站維護(hù)、網(wǎng)頁(yè)設(shè)計(jì)公司小程序開(kāi)發(fā)、定制開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司
日韩欧美一区精品在线观看| 91老熟女露脸大合集| 永久免费看黄在线观看| 麻豆av久久一区二区| 亚洲欧美韩国日本成人综合| 一本久久综合亚洲鲁鲁五月天| 亚洲精品午夜福利网| 亚洲最新精品一区二区| 日韩视频精品推荐一区二区| 国产美女直播亚洲一区色| 久久久精品免费中文视频| 国产91黑丝视频在线观看| 麻豆国产传媒69国产| 少妇一区二区三区免费| 日韩精品一区二区视频在线| 黄片小视频在线免费播放| 天天操夜夜骑日日干| 一区二区三区国产精品乱码| 99热视频这里只有精品| 性色av人妻中文一区二区| 亚洲国产第一尤物视频| 久久精品女人天堂av免费观看| 亚州精品少妇久久久久久| 天堂av在线播放观看| 国产成人综合亚洲不卡| 日韩在线电影二区三区| 日本高清免费黄色录像| 91精品国产综合久久麻豆| 好看的中文字幕人妻少妇| 亚洲欧美一区二区国产| 欧美精品熟妇乱黑人最大| 久国产亚洲精品久久久极品| 亚洲国产精品一区二区av| 亚洲成人日韩欧美在线| 色哟哟网站在线观看入口| 亚洲高清有码在线观看| 中文字幕不卡在线观看不卡| 亚洲免费av一区在线观看| 加勒比东京热视频在线| 国产精品果亚洲av无人区一区| 国产一区二区黑丝美女|