How to add fixed-length characters before the accession number in all books of Koha
The library itself migrated the data to Koha ignoring the zero prefix and started circulation. 3 months later, when the library was using the barcode scanner for circulation purposes, it noticed that by scanning the barcode label of the book, which was created by the old software, which turned out to be unavailable in the system due to the barcode also have prefix number (zero ), where the number was printed in it does not have a zero prefix.
The library has 2 solutions, adding a zero to create a fixed length numeric number (here it’s a 6 digit number) in all books accession numbers, or regenerating the barcode label. We fixed it with the first solution by follow method.
“Before the action please make a backup of the MySQL DB”
Use the MySQL query
sudo mysql -uroot –p
use koha_library; ("library" Instance Name)
UPDATE items SET barcode = lpad(barcode , 6 , '0'); exit;
This will update all accession numbers to six-digit length numbers with ‘0’ as leading
If you want to reverse the above, use the below command to remove all leading zeros in the accession number
UPDATE items SET barcode = trim(LEADING '0' FROM barcode);
If we want to delete a prefix character from all books barcode have, for example, ‘GEN’ from all books the command will be
UPDATE items SET barcode = trim(LEADING 'GEN' FROM barcode);
If we want to delete a suffix character from all books barcode have, for example, GEN from all books the command will be
UPDATE items SET barcode = trim(TRAILING 'GEN' FROM barcode);