DB2中字符、数字和日期类型之间的转换(The transformation between characters, Numbers, and date types in DB2)
DB2中字符、数字和日期类型之间的转换(The transformation between characters, Numbers, and date types in DB2)
We are using DB2 or Oracle, often do the conversion between digital character types date three < - > < - >, then the DB2 and Oracle, they are how to achieve it? The conversion between the several types of Oracle is very convenient, through the to_char| to_date|to_number function to complete the type conversion. This section introduces some of the DB2 knowledge, from the Oracle turn DBA or developers, you can compare learning.
Conversion from numeric to character type
Test it:
SQL>create, table, test_datatypeSQL> (SQL>col_a, smallint, SQL>col_b, integer, SQL>col_c, bigint, SQL>col_d, decimal (8,2), SQL>col_e, doubleSQL>); the DB20000I SQL command is successfully completed.
SQL>insert into test_datatype values (1,2030004000.4455555); the DB20000I SQL command is successfully completed.
SQL>describe select * from test_datatype column information
Number of columns: 5
SQL type type length column name length
------------------------------------------------------------------------
501 SMALLINT 2 COL_A 5
497 INTEGER 4 COL_B 5
493 BIGINT 8 COL_C 5
485 DECIMAL 8, 2 COL_D 5
481 DOUBLE 8 COL_E 5
SQL>select * from test_datatype; COL_A, COL_B, COL_C, COL_D, COL_E
-----------------------------------------------------------------------
12030004000.44 +5.55550000000000E+004
The 1 record has been selected.
SQL>select, char (col_a), char (col_b), char (col_c), digits (col_d), char (cast (col_e, as, decimal (8,2))) from test_datatype; 12345
-------------------------------------------------------
120300000400044, 55555
The 1 record has been selected.
SQL>select char (col_a) ||','||char (col_b) ||','||char (col_c) ||','||digits (col_d) ||','||char (cast (col_e as decimal from test_datatype (8,2))); 1
-----------------------------------------------------------
1, 20, 3000, 400044055555
The 1 record has been selected.
SQL> character to digital conversion
The col_a field in DB2
Field type numeric type