I have a table call lp_upload and it contains the plate number of the car and other relevant information:
CREATE TABLE `lp_upload` ( `date` date NULL , `plate` char(10) NULL , `site` int NULL , `dateid` char(20) NULL ) ;
This table receives information from the traffic camera. however, some letter in the plate is not recognized, and it will be replaced by $. So if the plate is really abc123, but the camera did not recognize c and 1, it will be ac $$ 23, which will go into the table.
im suppose that so when a new plate is introduced, and its 6 letters correspond to an existing plate, it will become one. EX: 123 $ 5678 entered and 12345678 already exist, then 123 $ 5678 will be replaced by 12345678.
so I wrote the matching function first:
CREATE DEFINER = CURRENT_USER FUNCTION `matchingfun`(`str1` char(10),`str2` char(10)) RETURNS int BEGIN DECLARE myindex int DEFAULT 0; DECLARE count int DEFAULT 0; DECLARE maxlength int; SET maxlength = length(str1); for_loop: LOOP SET myindex = myindex + 1; IF maxlength < myindex then RETURN 0; END IF; IF SUBSTRING(str1,myindex,1)= SUBSTRING(str2,myindex,1)then SET count = count +1; END IF; IF count > 6 then RETURN 1; END IF; IF SUBSTRING(str1,myindex,1)!= SUBSTRING(str2,myindex,1) and SUBSTRING(str1,myindex,1)!= '$' and SUBSTRING(str2,myindex,1)!= '$'then RETRUN 0; END IF; END LOOP for_loop; RETURN 0; END
and I added a trigger function to the table
CREATE TRIGGER `trigger1` AFTER INSERT ON `lpr_opt_upload` BEGIN declare old_site_id int; declare old_text char(10); select lpr_text into old_text from lpr_opt_upload where matchingfun(new.lpr_text, lpr_text) = 1; if(old_text is not null) then set new.lpr_text = old_text; end if; END
when i run this, the database crashes. You can solve this problem or suggest a better way to do it. Thank you