I have to compare two Varchar2 in PL/SQL, but in blocks of 3 characters. For example, the following two strings: "Synchronize" and "front" would match because both contain the substring "ron".
To solve this issue, I could get all blocks of three consecutive characters of the first string and look for any of them in the second string.
My question: Is there an easier/optimize solution to get the same result in PL/SQL?
Thanks in advance.
Below, you can find a sample of code in which v_found would contain a value greater than 0 if there is a match:
DECLARE
v_string1 VARCHAR2(30) := '1234567';
v_string2 VARCHAR2(30) := 'abcd345efg';
v_substring VARCHAR2 (100);
v_len PLS_INTEGER;
v_found PLS_INTEGER;
BEGIN
v_len := LENGTH(v_string1);
IF (v_len > 2 ) THEN
FOR i IN 1 .. v_len - 2
LOOP
v_substring := SUBSTR( v_string1, i, 3 );
dbms_output.put_line( v_substring );
v_found := INSTR( v_string2, v_substring );
dbms_output.put_line( 'v_string2<' || v_string2 || '>, v_substring<' || v_substring || '>, v_found <' || v_found || '>' );
END LOOP;
END IF;
END;