postgresql和oracle數(shù)據(jù)庫有什么不同

這篇文章主要介紹postgresql和oracle數(shù)據(jù)庫有什么不同,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

成都創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、麻栗坡網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站商城網(wǎng)站制作、集團公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為麻栗坡等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

Postgresql與Oracle相關(guān)差異對比

通過查閱資料及實驗,以下對比了 Postgresql 9.3 版本與 Oracle 11g版本的相關(guān)差異。注意:相關(guān)細節(jié)仍待考證和完善。

1、基本語法差異

1.1 基本數(shù)據(jù)類型差異

postgresql和oracle數(shù)據(jù)庫有什么不同

1.2 基本函數(shù)差異

postgresql和oracle數(shù)據(jù)庫有什么不同

1.2.1 游標屬性

postgresql和oracle數(shù)據(jù)庫有什么不同

1.2.2 系統(tǒng)內(nèi)置函數(shù)包

postgresql和oracle數(shù)據(jù)庫有什么不同

1.3 DDL差異

1.3.1 Sequence語法及使用差異

postgresql和oracle數(shù)據(jù)庫有什么不同

注意:pgsql中的dual,需自主實現(xiàn)。詳見兼容性設(shè)置->虛表dual問題 章節(jié)。

1.3.2 constraint差異

postgresql和oracle數(shù)據(jù)庫有什么不同

2、高級語法差異

2.1 事務(wù)差異

Oracle中,通過commit/rollback來實現(xiàn)事務(wù)提交或回滾。結(jié)構(gòu)類似于:

begin
    select ...
    update ...
    delete ...
    commit;
exception
    when others then
    rollback;
end;

PostgreSQL實際上把每個SQL語句當做在一個事務(wù)中執(zhí)行來看待。 如果你沒有發(fā)出BEGIN命令,那么每個獨立的語句都被一個隱含的BEGIN和(如果成功的話)COMMIT包圍。一組包圍在BEGIN和COMMIT之間的語句有時候被稱做事務(wù)塊。

例如:

BEGIN;
UPDATE accounts SET balance = balance - 100.00
    WHERE name = 'Alice';
SAVEPOINT my_savepoint;
UPDATE accounts SET balance = balance + 100.00
    WHERE name = 'Bob';
-- 呀!加錯錢了,應(yīng)該用 Wally 的賬號
ROLLBACK TO my_savepoint;
UPDATE accounts SET balance = balance + 100.00
    WHERE name = 'Wally';
COMMIT;

在PL/pgSQL中,也提供了類似于Oracle的Begin、End及ExceptionCode處理機制。他們之間的差異不明顯。事實上,PL/SQL(Oracle數(shù)據(jù)庫操作語言)與PL/pgSQL是高度相似的,這讓procedure在Oracle與 Postgresql之間遷移變得極為便捷。

2.2 函數(shù)繼承與重載

Oracle不支持繼承和重載特性,pgsql支持繼承和函數(shù)重載;

2.3 類型轉(zhuǎn)換

pgsql中的類型轉(zhuǎn)換“::”符,Oracle不支持。

2.4 子查詢

子查詢,pgsql要求更嚴格,必須具有別名才可以。

3、其他差異

3.1 jdbc差異

Oracle的jdbc連接字符串:db.url=jdbc:oracle:thin:@192.168.1.1:1521:ORCL

Postgresql的連接字符串:db.url=jdbc:postgresql:@192.168.1.1:5432/database

4、兼容性設(shè)置

4.1 字符串連接兼容性解決方案

Postgresql中沒有concat函數(shù),且由于||無法使用,需要通過在public schema中創(chuàng)建concat函數(shù)來解決。

--在 public schema中創(chuàng)建 concat 函數(shù)
create or replace function concat(text, text) returns text as
$body$ select coalesce($1,'') || coalesce($2,'')$body$ language 'sql' volatile;

alter function concat(text, text) owner to postgres;

4.2 虛表dual問題

Postgresql中沒有dual虛擬表,為保證兼容性,需創(chuàng)建偽視圖(view)代替:

create or replace view dual as
select NULL::"unknown"
where 1=1;

alter table dual owner to postgres;
grant all on table dual to postgres;
grant select on table dual to public;

4.3 數(shù)據(jù)分頁問題

Oracle中沒有 limit,postgresql中沒有rownum。需重寫相關(guān)語句。

-- Oracle
select * from (
  select * from (
    select * from t1 order by col1, col2
  ) where rownum <=50 order by col3, col4
) where rowmun <=20 order by col5, col6;
-- postgresql
select * from (select * from (select * from t1 order by col1, col2) ta order by col3, col4 limit 50) tb
order by col5, col6 limit 20;

注意:limit必須用于 order by 之后!

以上是postgresql和oracle數(shù)據(jù)庫有什么不同的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文名稱:postgresql和oracle數(shù)據(jù)庫有什么不同
轉(zhuǎn)載源于:http://muchs.cn/article6/ghegig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、網(wǎng)頁設(shè)計公司、關(guān)鍵詞優(yōu)化、域名注冊網(wǎng)站內(nèi)鏈、外貿(mào)網(wǎng)站建設(shè)

廣告

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

小程序開發(fā)