Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
brought up the answer for me atMySQL match part of string
SELECT *
FROM daTable
WHERE INSTR('abcd1234',daColumn) > 0
AND LENGTH(daColumn) = 4
WHERE INSTR('abcd1234',daColumn)
WHERE INSTR(daColumn,'abcd1234')
WHERE INSTR(newpassword,SUBSTRING(oldpassword,1,4) > 0
OR INSTR(newpassword,SUBSTRING(oldpassword,2,4) > 0
OR INSTR(newpassword,SUBSTRING(oldpassword,3,4) > 0
OR INSTR(newpassword,SUBSTRING(oldpassword,4,4) > 0
OR INSTR(newpassword,SUBSTRING(oldpassword,5,4) > 0
delimiter $$
[b]create[/b] [b]function[/b] partialmatch[teal]([/teal]one [maroon]varchar[/maroon][teal]([/teal][purple]100[/purple][teal]),[/teal]two [maroon]varchar[/maroon][teal]([/teal][purple]100[/purple][teal]))[/teal]
returns [maroon]varchar[/maroon][teal]([/teal][purple]100[/purple][teal])[/teal]
deterministic
no sql
[b]begin[/b]
[b]declare[/b] len1 [maroon]int[/maroon] [b]default[/b] length[teal]([/teal]one[teal]);[/teal]
[b]declare[/b] len2 [maroon]int[/maroon] [b]default[/b] length[teal]([/teal]two[teal]);[/teal]
[b]declare[/b] len [maroon]int[/maroon] [b]default[/b] len1[teal];[/teal]
[b]declare[/b] pos [maroon]int[/maroon][teal];[/teal]
[b]declare[/b] sub [maroon]varchar[/maroon][teal]([/teal][purple]100[/purple][teal]);[/teal]
[b]while[/b] len[teal]>[/teal][purple]0[/purple] [b]do[/b]
[b]set[/b] pos[teal]=[/teal][purple]1[/purple][teal];[/teal]
[b]while[/b] pos[teal]<=[/teal]len1[teal]-[/teal]len[teal]+[/teal][purple]1[/purple] [b]do[/b]
[b]set[/b] sub[teal]=[/teal]substring[teal]([/teal]one[teal],[/teal]pos[teal],[/teal]len[teal]);[/teal]
[b]if[/b] instr[teal]([/teal]two[teal],[/teal]sub[teal])!=[/teal][purple]0[/purple] [b]then[/b]
[b]return[/b] sub[teal];[/teal]
[b]end[/b] [b]if[/b][teal];[/teal]
[b]set[/b] pos[teal]=[/teal]pos[teal]+[/teal][purple]1[/purple][teal];[/teal]
[b]end[/b] [b]while[/b][teal];[/teal]
[b]set[/b] len[teal]=[/teal]len[teal]-[/teal][purple]1[/purple][teal];[/teal]
[b]end[/b] [b]while[/b][teal];[/teal]
[b]return[/b] [b]null[/b][teal];[/teal]
[b]end[/b][teal];[/teal]
$$
delimiter [teal];[/teal]
[b]select[/b] partialmatch[teal]([/teal]password_field[teal],[/teal][green][i]'new_password'[/i][/green][teal])[/teal] [b]from[/b] user_table [b]where[/b] id[teal]=[/teal][purple]42[/purple][teal];[/teal]
The simplest is to get the returned value's length :MikeM2468 said:What would I need to do to get it return a numeric value for the number of consecutive characters that match?
[b]select[/b] [highlight]coalesce[teal]([/teal]length[teal]([/teal][/highlight]partialmatch[teal]([/teal]password_field[teal],[/teal][green][i]'new_password'[/i][/green][teal])[/teal][highlight][teal]),[/teal][purple]0[/purple][teal])[/teal][/highlight] [b]from[/b] user_table [b]where[/b] id[teal]=[/teal][purple]42[/purple][teal];[/teal]
delimiter $$
[b]create[/b] [b]function[/b] partialmatch[teal]([/teal]one [maroon]varchar[/maroon][teal]([/teal][purple]100[/purple][teal]),[/teal]two [maroon]varchar[/maroon][teal]([/teal][purple]100[/purple][teal]))[/teal]
returns [highlight][maroon]int[/maroon][/highlight]
deterministic
no sql
[b]begin[/b]
[b]declare[/b] len1 [maroon]int[/maroon] [b]default[/b] length[teal]([/teal]one[teal]);[/teal]
[b]declare[/b] len2 [maroon]int[/maroon] [b]default[/b] length[teal]([/teal]two[teal]);[/teal]
[b]declare[/b] len [maroon]int[/maroon] [b]default[/b] len1[teal];[/teal]
[b]declare[/b] pos [maroon]int[/maroon][teal];[/teal]
[b]declare[/b] sub [maroon]varchar[/maroon][teal]([/teal][purple]100[/purple][teal]);[/teal]
[b]while[/b] len[teal]>[/teal][purple]0[/purple] [b]do[/b]
[b]set[/b] pos[teal]=[/teal][purple]1[/purple][teal];[/teal]
[b]while[/b] pos[teal]<=[/teal]len1[teal]-[/teal]len[teal]+[/teal][purple]1[/purple] [b]do[/b]
[b]set[/b] sub[teal]=[/teal]substring[teal]([/teal]one[teal],[/teal]pos[teal],[/teal]len[teal]);[/teal]
[b]if[/b] instr[teal]([/teal]two[teal],[/teal]sub[teal])!=[/teal][purple]0[/purple] [b]then[/b]
[b]return[/b] [highlight]len[/highlight][teal];[/teal]
[b]end[/b] [b]if[/b][teal];[/teal]
[b]set[/b] pos[teal]=[/teal]pos[teal]+[/teal][purple]1[/purple][teal];[/teal]
[b]end[/b] [b]while[/b][teal];[/teal]
[b]set[/b] len[teal]=[/teal]len[teal]-[/teal][purple]1[/purple][teal];[/teal]
[b]end[/b] [b]while[/b][teal];[/teal]
[b]return[/b] [highlight][purple]0[/purple][/highlight][teal];[/teal]
[b]end[/b][teal];[/teal]
$$
delimiter [teal];[/teal]