Operations and Functions for Bit Strings
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:
- Concatenation (the "||" operation) - Returns a bit string
made by joining the specified strings.
- SUBSTRING - Returns a bit string made by extracting a portion of the specified
string according to the specified position and the specified length.
- BIT_LENGTH - Returns a number indicating the number of bits of
the specified string.
- Comparison (the ">" or "<" operation) - Returns true or false by comparing each
bit of the first operand with the bit of the second operand at the same position
according to a predefined collating sequence.
- "=" operation - Returns true if each bit of the first operand is equal to the
bit of the second operand at the same position according to a predefined collating sequence.
- POSITION - Returns a number indicating the position of a short string
inside a long string.
Examples of bit strings tested on MySQL only, BitStringOps.sql:
-- Copyright (c) 1999 HerongYang.com. All Rights Reserved.
SELECT BINARY('Hello'); -- BINARY() is not part of SQL-92
-- SELECT CONCAT(X'4',X'1'); -- X'..' takes double hex digits only
-- SELECT SUBSTRING(BINARY(X'41424344'),16,32); -- Not at bit level
SELECT 'xyz ' = 'XYZ';
SELECT BINARY('xyz') = BINARY('XYZ');
Run BitStringOps.sql on MySQL 8.0 server, you will get:
herong> %mysql%\bin\mysql --user=root --password=TopSecret test \
'xyz ' = 'XYZ'
BINARY('xyz') = BINARY('XYZ')
A number of interesting things to note here:
- MySQL seems to not taking B'10000001' as X'41'. So you can not really enter a bit string
that is not 8*n bits long.
- BINARY() is a MySQL function. I can not find it in SQL-92.
- X'..' takes only 2*n hex digits.
- SUBSTRING() works at character string level, not at bit string level.
- '=' operator works at binary level as well as character level depending on the context.
Table of Contents
About This Book
Introduction of SQL
MySQL Introduction and Installation
Introduction of MySQL Programs
PHP Programs and MySQL Server
Perl Programs and MySQL Servers
Java Programs and MySQL Servers
Datatypes and Data Literals
Operations and Expressions
►Character Strings and Bit Strings
Operations and Functions for Character Strings
►Operations 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
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Locks Used in MySQL
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
MySQL Server Administration
Storage Engines in MySQL Server
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
Bulk Changes on Large Tables
MySQL Server on macOS
Installing MySQL Server on Linux
Connection, Performance and Second Instance on Linux
Full Version in PDF/EPUB