db2 資料型別

2021-09-07 08:42:22 字數 3098 閱讀 6683

資料型別:

字串型別

描述character(n)

n bytes定長字串. n 大於0 不大於255. 預設 1.

varchar(n)

變長字串,最大 n bytes. n大於 0 小於表空間的 page size. 最大32704.

clob(n)

變長字串,最大2 147 483 647.預設1.

graphic(n)

定長圖形字串, n 個雙位元組字元. n 大於 0 小於128. 預設 1.

vargraphic(n)

變長圖形字串. 最大長度 n, 大於0小於表空間的page size. 最大16352.

dbclob(n)

雙位元組變長字串, n不能超過 1 073 741 824.預設1.

binary(n)

定長或變長二進位制字串. n 大於 0 不大於 255. 預設1.

varbinary(n)

變長二進位制字串,n大於 0小於表空間的 page size. 最大 32704.

blob(n)

變長二進位制字串,n 不大於 2 147 483 647. 預設 1.

數值型別

描述smallint

小整數,精度(即通常說的長度) 15 bits. 範圍 -32768 到 +32767.

integer or

int整數,精度 31 bits的二進位制整數,範圍 -2147483648 到 +2147483647.

bigint

大整數,精度 63 bits二進位制整數,範圍 -9223372036854775808 到 +9223372036854775807.

decimal or

numeric

壓縮十進位制數,小數點位置由precision和scale決定,scale非負且小於精度.最大精度 31 digits. decimal 列中的值有同樣的precision 和 scale.範圍 1 - 10³¹ 到 10³¹ - 1.

decfloat

十進位制浮點數,最大精度 34 位.(早期db2版本不支援)

real

單精度浮點數,32 bits.範圍大約為 -7.2e+75 到 7.2e+75.最大負值約為 -5.4e-79, 最小正值約為 5.4e-079.

double

雙精度浮點數,64-bits. 範圍大約為 -7.2e+75 到 7.2e+75.最大負值約為 -5.4e-79, 最小正值約為 5.4e-079.

時間日期型別

描述date

年月日組成的日期,範圍 0001-01-01 到 9999-12-31.

time

時分秒組成的時間,範圍 00.00.00 到 24.00.00.

timestamp

年月日時分秒微妙組成的時間,範圍 0001-01-01-00.00.00.000000000 到 9999-12-31-24.00.00.000000000 精確到納秒. 可儲存時區資訊

distinct types:使用者自定義型別,是基於db2內建型別的別名,但db2會將其作為不同的型別進行處理。例如:

create distinct type us_dollar as decimal (9,2);

create distinct type canadian_dollar as decimal (9,2);

系統預設值:型別型別

default

數值smallint, integer, bigint, decimal, numeric, real, double, decfloat, or float

0定長字串

char or graphic binary

空格 十六進製制0

變長字串

varchar, clob, vargraphic, dbclob, varbinary, or blob

空串日期

date

當前日期

時間time

當前時間

時間日期

timestamp

當前 timestamp

rowids

rowid

db2生成

關於alter column:

db2支援alter table alter column...但列屬性的更改需要分開操作:

[sql]view plain

copy

1.更改型別(設定為主鍵的列不能更改型別)  

alter table "schema"."tablename" alter column "col" set data type varchar(32);  

2.更改預設值  

alter table "schema"."tablename" alter column "col" set default 'abc';  

系統預設值:  

alter table "schema"."tablename" alter column "col" set default; --設定預設值  

alter table "schema"."tablename" alter column "col" drop default; --刪除預設值  

3.更改是否允許空值  

alter table "schema"."tablename" alter column "col" set not null;  

alter table "schema"."tablename" alter column "col" drop not null;  

更改列型別,是否允許空值後,需要執行reorg table "tablename";  

更改預設值後,通常需要執行update "schema"."tablename" set "col" = default where "col" is null;  

部分內容引自:

DB2資料型別

char 定長的阿拉伯字元資料 varchar 變化的阿拉伯字元資料 graphic 定長的圖形資料 vargraphic 變長的圖形資料 allint 短整形數 decimal 數值型資料 integer 長整形數 float n float 單精度浮點數 n 21 date 日曆日期型資料 fl...

DB2資料型別

db2資料庫的內建資料型別主要分成數值型 numeric 字串型 character string 圖形字串 graphic string 二進位制字串型 binary string 或日期時間型 datetime 還有一種叫做 datalink 的特殊資料型別。datalink 值包含了對儲存在資...

DB2資料型別

db2 資料型別 2009 07 09 下午 03 23 1 概述 db2 提供了一套豐富且靈活的資料型別。db2 附帶 integer char 和 date 等基本資料型別。它還提供了建立使用者定義的資料型別 udt 的工具,使使用者能夠建立複雜的非傳統的資料型別,從而適應當今複雜的程式設計環境...