Oracle數(shù)據(jù)庫中的字節(jié)序格式是什么?
2023-04-04 10:19 瀟湘隱者 閱讀(350) 評論(0) 收藏 舉報前言:本文是對這篇博客What is the endian format in Oracle databases?[1]的翻譯,如有翻譯不當?shù)牡胤剑凑堈徑猓堊鹬卦瓌?chuàng)和翻譯勞動成果,轉(zhuǎn)載的時候請注明出處。謝謝!
英文地址:https://dbtut.com/index.php/2019/06/27/what-is-the-endian-format-in-oracle-databases/
什么是字節(jié)序?
字節(jié)序(Endian)是多字節(jié)數(shù)據(jù)類型在內(nèi)存中的存儲方式。換句話說,它決定了數(shù)據(jù)的字節(jié)順序。有兩種字節(jié)序,小字節(jié)序(Little Endian)和大字節(jié)序(Big Endian)。
小字節(jié)序
數(shù)據(jù)先存儲小端。也就是說,第一個字節(jié)是最大的。
另外一種翻譯:將低序字節(jié)存儲在起始地址。
大字節(jié)序
數(shù)據(jù)先存儲大端。即第一個字節(jié)是最小的。
另外一種翻譯:高序字節(jié)存儲在起始地址。
例如:
假設(shè)一個整數(shù)存儲為4個字節(jié)(32位),那么一個值為0x01234567(十進制表示)的變量將以0x01、0x23、0x45、0x67的形式存儲。在具有大端的系統(tǒng)中,此數(shù)據(jù)按此順序存儲,而在小端系統(tǒng)中,它以相反的順序存儲。

Little Endian 和 Big Endian 的區(qū)別
下圖顯示了大端和小端的區(qū)別。

在 Oracle 數(shù)據(jù)庫中,字節(jié)序格式由其工作環(huán)境中的字節(jié)序信息決定。數(shù)據(jù)庫中的字節(jié)序格式告訴我們相關(guān)數(shù)據(jù)庫可以移動到哪些環(huán)境。在不同的端序環(huán)境之間使用常規(guī)方法移動數(shù)據(jù)庫是不可能的。例如,您不能用Data Guard 將數(shù)據(jù)庫從 Little Endian系統(tǒng)傳輸?shù)骄哂蠦ig Endian的系統(tǒng)。
您可以用以下SQL查看數(shù)據(jù)庫中的當前字節(jié)序格式。
SQL> select name,platform_id,platform_name from v$database;
NAME PLATFORM_ID PLATFORM_NAME
--------- ----------- ----------------------------------------------------------
ORCL 13 Linux x86 64-bit
以下查詢顯示了可以移動現(xiàn)有數(shù)據(jù)庫的其他環(huán)境。
大端格式 (IBM AIX)
SQL> set lines 200
SQL> set pages 200
SQL> COL "Source" FORM a32
SQL> COL "Compatible Targets" FORM a40
SQL> select d.platform_name "Source", t.platform_name "Compatible Targets", endian_format
from v$transportable_platform t, v$database d where t.endian_format = (select endian_format from v$transportable_platform t, v$database d where d.platform_name = t.platform_name)
order by "Compatible Targets";
Source Compatible Targets ENDIAN_FORMAT
-------------------------------- ---------------------------------------- ------------------------------------------
AIX-Based Systems (64-bit) AIX-Based Systems (64-bit) Big
AIX-Based Systems (64-bit) Apple Mac OS Big
AIX-Based Systems (64-bit) HP-UX (64-bit) Big
AIX-Based Systems (64-bit) HP-UX IA (64-bit) Big
AIX-Based Systems (64-bit) IBM Power Based Linux Big
AIX-Based Systems (64-bit) IBM zSeries Based Linux Big
AIX-Based Systems (64-bit) Solaris[tm] OE (32-bit) Big
AIX-Based Systems (64-bit) Solaris[tm] OE (64-bit) Big
8 rows selected.
小端格式 (Linux x86)
SQL> set lines 200
SQL> set pages 200
SQL> COL "Source" FORM a32
SQL> COL "Compatible Targets" FORM a40
SQL> select d.platform_name "Source", t.platform_name "Compatible Targets", endian_format
from v$transportable_platform t, v$database d where t.endian_format = (select endian_format from v$transportable_platform t, v$database d where d.platform_name = t.platform_name)
order by "Compatible Targets";
Source Compatible Targets ENDIAN_FORMAT
-------------------------------- ---------------------------------------- --------------
Linux x86 64-bit Apple Mac OS (x86-64) Little
Linux x86 64-bit HP IA Open VMS Little
Linux x86 64-bit HP Open VMS Little
Linux x86 64-bit HP Tru64 UNIX Little
Linux x86 64-bit Linux IA (32-bit) Little
Linux x86 64-bit Linux IA (64-bit) Little
Linux x86 64-bit Linux x86 64-bit Little
Linux x86 64-bit Microsoft Windows IA (32-bit) Little
Linux x86 64-bit Microsoft Windows IA (64-bit) Little
Linux x86 64-bit Microsoft Windows x86 64-bit Little
Linux x86 64-bit Solaris Operating System (x86) Little
Linux x86 64-bit Solaris Operating System (x86-64) Little
12 rows selected.
下面是上文的中的SQL語句:
SET lines 200
SET pages 200
COL "Source" FOR a32
COL "Compatible Targets" FOR a40
SELECT d.platform_name "Source",
t.platform_name "Compatible Targets",
endian_format
FROM v$transportable_platform t,
v$database d
WHERE t.endian_format =
(SELECT endian_format
FROM v$transportable_platform t,
v$database d
WHERE d.platform_name = t.platform_name)
ORDER BY "Compatible Targets";
參考資料
原文地址: https://dbtut.com/index.php/2019/06/27/what-is-the-endian-format-in-oracle-databases/
浙公網(wǎng)安備 33010602011771號