Home   Oracle SQL Scripts   Contact link Contact:  jack@dughaille.info

Description:
Compare two strings

Example output:
SQL> @cstrings String one: A long, long way to Tipperary String two: A long, 1ong way to Tipperary asc chr asc chr result --- --- --- --- ------ 65 A = 32 = 108 l = 111 o = 110 n = 103 g = 44 , = 32 = 108 l 49 1 111 o = 110 n = 103 g = 32 = 119 w = 97 a = 121 y = 32 = 116 t = 111 o = 32 = 84 T = 105 i = 112 p = 112 p = 101 e = 114 r = 97 a = 114 r = 121 y = PL/SQL procedure successfully completed.

Script:
prompt prompt prompt accept s1 prompt "String one: " prompt accept s2 prompt "String two: " prompt prompt declare ls1 varchar2( 32000 ) := '&&s1'; ls2 varchar2( 32000 ) := '&&s2'; ls_out varchar2( 32000 ); begin dbms_output.put_line( ' asc chr asc chr result' ); dbms_output.put_line( ' --- --- --- --- ------' ); for i in 1..length( ls1 ) loop ls_out := to_char( ascii( substr( ls1, i, 1 ) ), '99999' ); if i <= length( ls2 ) then if ascii( substr( ls1, i, 1 ) ) = ascii( substr( ls2, i, 1 ) ) then ls_out := ls_out || ' ' || lpad( substr( ls1, i, 1 ), 5 ) || rpad( ' ', 19 ) || '='; else ls_out := ls_out || ' ' || lpad( substr( ls1, i, 1 ), 5 ) || ' ' || to_char( ascii( substr( ls2, i, 1 ) ), '99999' ) || ' ' || lpad( substr( ls2, i, 1 ), 5 ); end if; end if; dbms_output.put_line( ls_out ); end loop; end; / prompt