Operatins and Functions for Bit Strings

This section describes operations and functions for bit strings, sequences of bit values, 0 and 1.

A bit string is a sequence of bits, each having the value of 0 or 1.

Operations involving bit strings are:

Examples of bit strings tested on MySQL only, BitStringOps.sql:

-- BitStringOps.sql
-- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
--
SELECT BINARY('Hello'); -- BINARY() is not part of SQL-92
SELECT BINARY(X'41424344'); 
-- SELECT CONCAT(X'4',X'1'); -- X'..' takes double hex digits only
-- SELECT SUBSTRING(BINARY(X'41424344'),16,32); -- Not at bit level
SELECT LENGTH('Hello'); 
SELECT BIT_LENGTH('Hello'); 
SELECT 'xyz ' = 'XYZ'; 
SELECT BINARY('xyz') = BINARY('XYZ');

Run BitStringOps.sql on MySQL 5.7 server, you will get:

C:\herong>set "MySQL=\Program Files\MySQL\MySQL Server 5.7"
C:\herong>"%MySQL%\bin\mysql" --user=root --password=TopSecret test 
   < BitStringOps.sql
BINARY('Hello')
Hello
BINARY(X'41424344')
ABCD
SUBSTRING(BINARY(X'41424344'),16,32)

LENGTH('Hello')
5
BIT_LENGTH('Hello')
40
'xyz ' = 'XYZ'
1
BINARY('xyz') = BINARY('XYZ')
0

A number of interesting things to note here:

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

 PHP Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

Character Strings and Bit Strings

 Operatins and Functions for Character Strings

Operatins and Functions for Bit Strings

 Commonly Used Functions

 Table Column Types for Different Types of Values

 Using DDL to Create Tables and Indexes

 Using DML to Insert, Update and Delete Records

 Using SELECT to Query Database

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version