MySQL BIN function is one of the String Functions, which is to return the string representation of the binary value of a number. The basic syntax of the MySQL BIN Function is as shown below:
SELECT BIN(Numeric_Expression) FROM [Source]
Numeric_Expression: Please specify a valid Expression or Number. It accepts up to BIG INT. To demonstrate this, We are going to use the customer details table data that we showed below
MySQL BIN Function Example
The String BIN returns the Binary Values of the given numeric expression. The following query shows multiple ways to use this function.
SELECT BIN(12); SELECT BIN(4029); -- Let me use NULL value as input SELECT BIN(NULL); -- It Omits the decimal values SELECT BIN(12.56); SELECT BIN('A');
In this method example, we are going to implement it on different columns in a table. The following MySQL statement returns the Binary values of the data present in the Yearly_Income and Sales Columns.
USE company; SELECT First_Name, Last_Name, Education, Profession, Yearly_Income, BIN(Yearly_Income) AS Binary_Income, Sales, BIN(Sales) AS Binary_Sales FROM customerdetails;