MySQL’s CAST() and CONVERT() functions can be used to take a value of one type and produce a value of another. The syntax is as follows:

CAST(value as type);
 
CONVERT(value, type);
Copy the code

Binary: There is a limit to the types that binary can convert. This type can be one of the following values:

It is a character with parameters: CHAR() DATE: DATETIME: TIME DATETIME type: DATETIME Floating point: DECIMAL Integer: SIGNED UNSIGNED integer: UNSIGNEDCopy the code

Example:

Description: The product_cat_rank table live_id is an int, and the user_Permission table access_key is a char. The two tables are associated by live_id and access_key.

Dlpcrd. live_id is an int. Select dlpcrd.id, vupfrom product_cat_rank dlpcrd 
join user_permission vup on vup.access_key = cast(dlpcrd.live_id as char)
where vup.access_key = '1234'; Dlpcrd. live_id is an int. Select dlpcrd.id, vupfrom product_cat_rank dlpcrd 
join user_permission vup on vup.access_key = convert(dlpcrd.live_id, char)
where vup.access_key = '1234';

Copy the code