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 BIN Function in MySQL 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 string BIN function, We are going to use the customerdetails table data that we showed below
MySQL BIN Example 1
The String BIN in MySQL returns the Binary Values of the given numeric expression. The following BIN 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');
String BIN Function Example 2
In this String Function example, we are going to implement the MySQL string BIN on different columns in a table. The following MySQL statement returns the Binary values of the data present in Yearly_Income and Sales Columns.
-- MySQL String BIN Example 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;