MySQL BIN is one of the String Function, which is used to return the string representation of binary value of a number. In this article we will show you, How to use this string BIN in MySQL with example.
MySQL BIN Syntax
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.
In order to demonstrate this string function, We are going to use the customerdetails table data that we shown below
MySQL BIN Example 1
The BIN Function in MySQL is used to return the Binary Values of the given numeric expression. The following query will show 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');
MySQL BIN Function Example 2
In this example, we are going to implement the string BIN function in MySQL on different columns in a table. Following statement will return 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;
Thank You for Visiting Our Blog