3 Wrz 2008

Wykorzystanie LOCATE i REGEXP

SELECT LOCATE( ' ', address ) pos, address, SUBSTRING_INDEX(address, ' ', -1), address REGEXP '[:digit:]' FROM hotele
SELECT LOCATE( ' ', address ) pos, address, SUBSTRING_INDEX( address, ' ', -1 ) , address REGEXP '[[:digit:]]' FROM hotele
SELECT LOCATE( ' ', address ) pos, address, SUBSTRING_INDEX( address, ' ', -1 ) , address REGEXP '[[:digit:]]' FROM hotele WHERE SUBSTRING_INDEX( address, ' ', -1 ) REGEXP '[[:digit:]]'
update hotele set nr_domu = SUBSTRING_INDEX( address, ' ', -1 ) WHERE SUBSTRING_INDEX( address, ' ', -1 ) REGEXP '[[:digit:]]'
SELECT LOCATE( ' ', REVERSE(address) ) pos, address, trim(SUBSTRING( address, 1, LENGTH(address) - LOCATE( ' ', REVERSE(address) ))) FROM hotele WHERE SUBSTRING_INDEX( address, ' ', -1 ) REGEXP '[[:digit:]]'
update hotele set ulica = trim(SUBSTRING( address, 1, LENGTH(address) - LOCATE( ' ', REVERSE(address) ))) WHERE SUBSTRING_INDEX( address, ' ', -1 ) REGEXP '[[:digit:]]'