隐式类型转换
定长字符串与数值类型转换
定长字符串类型CHARACTER与NUMBER/NUMERIC,INT4,INT8,FLOAT4,FLOAT8之间相互转换。
atlasdb=# select '1'::CHARACTER =1::number; ?column? ---------- t (1 row) atlasdb=# select '1'::CHARACTER =1::numeric; ?column? ---------- t (1 row) atlasdb=# select '1'::CHARACTER =1::int4; ?column? ---------- t (1 row) atlasdb=# select '1'::CHARACTER =1::int8; ?column? ---------- t (1 row) atlasdb=# select '1'::CHARACTER =1::float4; ?column? ---------- t (1 row) atlasdb=# select '1'::CHARACTER =1::float8; ?column? ---------- t (1 row)
变长字符串类型与数值类型转换
VARCHAR/VARCHAR2与NUMBER/NUMERIC,INT8,FLOAT4,FLOAT8之间相互转换。
atlasdb=# select '1'::varchar2 =1::NUMERIC; ?column? ---------- t (1 row) atlasdb=# select '1'::varchar2 =1::INT8; ?column? ---------- t (1 row) atlasdb=# select '1'::varchar2 =1::FLOAT4; ?column? ---------- t (1 row) atlasdb=# select '1'::varchar2 =1::FLOAT8; ?column? ---------- t (1 row)
文本类型与数值类型转换
NUMBER/NUMERIC,INT2,INT4,INT8,FLOAT4,FLOAT8之间相互转换。
atlasdb=# select '1'::text =1::NUMBER; ?column? ---------- t (1 row) atlasdb=# select '1'::text =1::NUMERIC; ?column? ---------- t (1 row) atlasdb=# select '1'::text =1::INT2; ?column? ---------- t (1 row) atlasdb=# select '1'::text =1::INT4; ?column? ---------- t (1 row) atlasdb=# select '1'::text =1::INT8; ?column? ---------- t (1 row) atlasdb=# select '1'::text =1::FLOAT4; ?column? ---------- t (1 row) atlasdb=# select '1'::text =1::FLOAT8; ?column? ---------- t (1 row)
短整型INT2转换为字符串
INT2转化为CHARACTER,VARCHAR/VARCHAR2。
atlasdb=# select (1::int2)::varchar2; varchar2 ---------- 1 (1 row) atlasdb=# select (1::int2)::varchar; varchar --------- 1 (1 row) atlasdb=# select (1::int2)::character; bpchar -------- 1 (1 row)