ID MOBILE
1 9869600733
2 9869600793
3 9869600799
all id whose mobile number containing 9 three times(using string functions like replace, substr, etc)... ? (without like , % , etc)
You can use LEN and Replace
Where len(MOBILE)-len(replace(MOBILE ,'9',''))>=3
Note : Some DBMS uses LENGTH instead of LEN
Where length(MOBILE)-length(replace(MOBILE ,'9',''))>=3
replace(MOBILE ,'9','') will replace all the 9's with empty
stringlength(MOBILE) will count the number of characters in Mobile
columnlength(replace(MOBILE ,'9','')) will count the number of characters
in Mobile column as replacing 9's with empty stringlength(MOBILE)-length(replace(MOBILE ,'9','')) here the
difference will tell the number of missing characters that is our 9, you can use this difference to count the 9 exactly three '9's:
Select * from mytable
Where len(mobile) - len(replace(mobile, '9', '')) = 3
at least three '9's:
Select * from mytable
Where len(mobile) - len(replace(mobile, '9', '')) >= 3
9s removed, then it's length will be the length of the unmodified string minus the number of 9s that were removed.
like? That is the appropriate way to do this.