![]() ![]() If the value specified by expr is of the VARCHAR type and is not a number, a value of 0 is returned after the value is converted to the INT/INTEGER, SMALLINT, or TINYINT type.įor example, execute the following statement to convert the value China from the VARCHAR type to the SMALLINT type: SELECT CAST( 'China' AS SMALLINT) The following information is returned: NULL If the value specified by expr is of the VARCHAR type and is not a number, NULL is returned when the value is converted to the DECIMAL(M,D) or FLOAT type.įor example, execute the following statement to convert the value China from the VARCHAR type to the DECIMAL(M,D) type: SELECT cast( 'China' AS decimal(5,2)) If you convert a value of the DECIMAL(M,D), DOUBLE, or FLOAT type to the INT/INTEGER, SMALLINT, or TINYINT type, the value is rounded after the conversion.įor example, execute the following statement to convert the value 1.1342 from the FLOAT type to the INT type: SELECT CAST(1.1342 AS INT) ![]() If you convert a value of a high-precision data type to a low-precision data type, the value is rounded after the conversion.įor example, execute the following statement to convert the value 1.23456789 from the DOUBLE type to the FLOAT type: SELECT CAST(1.23456789 AS FLOAT) NULL is returned because 99999999 is not within the allowed value range of the SMALLINT type. If the value specified by expr is not within the allowed value range of the destination data type, null is returned during the conversion.įor example, execute the following statement to convert the value 99999999 from the BIGINT type to the SMALLINT type: SELECT CAST(99999999 as SMALLINT) +-+ CAST AS DECIMAL(m,d)|FLOAT|INT|INTEGER|SMALLINT|TINYINT CAST (expr AS ) DescriptionĬonverts the value specified by expr to the DECIMAL(M,D), FLOAT, INT, INTEGER, SMALLINT, or TINYINT type. The following information is returned: NULL Example 3Įxecute the following statement to convert the value 4.3 from the DOUBLE type to BOOLEAN type: SELECT CAST(4.3 AS BOOLEAN) Įxecute the following statement to convert the value 5 from the INT type to the BOOLEAN type: SELECT CAST(5 AS BOOLEAN) The following information is returned: +-+Įxecute the following statement to convert the value a from the VARCHAR type to the BOOLEAN type: SELECT CAST('a' AS BOOLEAN) If the source value is 0, a value of 0 is returned.Įxecute the following statement to convert the value 1 from the INT type to the BOOLEAN type: SELECT CAST('1' AS BOOLEAN) If the source value is a number other than 0, a value of 1 is returned. If the source value is 0.0, a value of 0 is returned. If the source value is a number other than 0.0, a value of 1 is returned. If the source value is of a different data type, NULL is returned. If the source value is false or 0, a value of 0 is returned. If the source value is true or 1, a value of 1 is returned. Source data typesĭECIMAL(M,D), FLOAT, INT/INTEGER, SMALLINT, or TINYINT You must specify this parameter.ĬAST AS BOOLEAN CAST (expr AS BOOLEAN) DescriptionĬonverts the value specified by expr to the BOOLEAN type. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |