1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| --------------
START TRANSACTION
--------------
--------------
set session collation_connection = "latin1_general_ci"
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE IF NOT EXISTS `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `product`
--------------
--------------
CREATE TABLE `product`
( `id` integer unsigned NOT NULL auto_increment Primary key,
`ean13` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
--------------
--------------
INSERT INTO `product` (`ean13`) VALUES
('7100000009319'),
('7120000009319'),
('7123000009319'),
('7123400009319')
--------------
--------------
select id,
ean13,
length(ean13) as longueur
from `product`
--------------
+----+---------------+----------+
| id | ean13 | longueur |
+----+---------------+----------+
| 1 | 7100000009319 | 13 |
| 2 | 7120000009319 | 13 |
| 3 | 7123000009319 | 13 |
| 4 | 7123400009319 | 13 |
+----+---------------+----------+
--------------
update `product` set ean13 = concat(left(`ean13`, instr(`ean13`, '0') - 1), right(`ean13`, 13 - instr(`ean13`, '0')))
--------------
--------------
select id,
ean13,
length(ean13) as longueur
from `product`
--------------
+----+--------------+----------+
| id | ean13 | longueur |
+----+--------------+----------+
| 1 | 710000009319 | 12 |
| 2 | 712000009319 | 12 |
| 3 | 712300009319 | 12 |
| 4 | 712340009319 | 12 |
+----+--------------+----------+
--------------
COMMIT
--------------
Appuyez sur une touche pour continuer... |
Partager