If data is inserted this way,
insert into `t` (`date`, `data`) values ( now(), lpad('Hello', 4096, CHAR(0x00)));
How do you retrive it removing NULL characters from data
column. I am infact looking for something that does the reverse of what LPAD
does.
The table definition is,
create table `t` (
`id` int auto_increment,
`date` datetime,
`data` blob,
primary key (`id`)
);
Generalized question is, How can I remove an specific character from either beginning or ending of a string?
Learn MySQL from scratch for Data Science and Analytics You can remove special characters from a database field using REPLACE() function.
To look for NULL values, you must use the IS NULL test. The following statements show how to find the NULL phone number and the empty phone number: mysql> SELECT * FROM my_table WHERE phone IS NULL; mysql> SELECT * FROM my_table WHERE phone = ''; See Section 3.3.
You can also use SELECT ... INTO OUTFILE with a VALUES statement to write values directly into a file. An example is shown here: SELECT * FROM (VALUES ROW(1,2,3),ROW(4,5,6),ROW(7,8,9)) AS t INTO OUTFILE '/tmp/select-values.
The LOWER() function converts a string to lower-case. Note: The LCASE() function is equal to the LOWER() function.
Use trim(), which comes in 3 flavours:
select trim(leading CHAR(0x00) from data)
or
select trim(trailing CHAR(0x00) from data)
or
select trim(both CHAR(0x00) from data)
You'd probably want to use TRIM, as in;
select id, date, trim(trailing char(0) from data) as data from t;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With