前言:本文是對這篇博客What is the endian format in Oracle databases?[1]的翻譯,如有翻譯不當的地方,敬請諒解,請尊重原創和翻譯勞動成果,轉載的時候請註明出處。謝謝! 英文地址:https://dbtut.com/index.php/2019/06/27 ...
前言:本文是對這篇博客What is the endian format in Oracle databases?[1]的翻譯,如有翻譯不當的地方,敬請諒解,請尊重原創和翻譯勞動成果,轉載的時候請註明出處。謝謝!
英文地址:https://dbtut.com/index.php/2019/06/27/what-is-the-endian-format-in-oracle-databases/
什麼是位元組序?
位元組序(Endian)是多位元組數據類型在記憶體中的存儲方式。換句話說,它決定了數據的位元組順序。有兩種位元組序,小位元組序(Little Endian)和大位元組序(Big Endian)。
小位元組序
數據先存儲小端。也就是說,第一個位元組是最大的。
另外一種翻譯:將低序位元組存儲在起始地址。
大位元組序
數據先存儲大端。即第一個位元組是最小的。
另外一種翻譯:高序位元組存儲在起始地址。
例如:
假設一個整數存儲為4個位元組(32位),那麼一個值為0x01234567(十進位表示)的變數將以0x01、0x23、0x45、0x67的形式存儲。在具有大端的系統中,此數據按此順序存儲,而在小端系統中,它以相反的順序存儲。
Little Endian 和 Big Endian 的區別
下圖顯示了大端和小端的區別。
在 Oracle 資料庫中,位元組序格式由其工作環境中的位元組序信息決定。資料庫中的位元組序格式告訴我們相關資料庫可以移動到哪些環境。在不同的端序環境之間使用常規方法移動資料庫是不可能的。例如,您不能用Data Guard 將資料庫從 Little Endian系統傳輸到具有Big Endian的系統。
您可以用以下SQL查看資料庫中的當前位元組序格式。
SQL> select name,platform_id,platform_name from v$database;
NAME PLATFORM_ID PLATFORM_NAME
--------- ----------- ----------------------------------------------------------
ORCL 13 Linux x86 64-bit
以下查詢顯示了可以移動現有資料庫的其他環境。
大端格式 (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/