50.1 DIFF Function

This function computes the difference between tables of lines. The implementation uses the default version of the longest common subexpression algorithm, without any optimizations. The DIFF function is not intended for very large inputs. The output is similar to the unified diff format.


    p_left    IN apex_t_varchar2,
    p_right   IN apex_t_varchar2,
    p_context IN PLS_INTEGER DEFAULT 3 )
    RETURN apex_t_varchar2;


Table 50-1 DIFF Function Parameters

Parameter Description
p_left The lines in the "left" table.
p_right The lines in the "right" table.
p_context The number of same lines after each diff to also return (default 3).


A table of varchar2, where the first character denotes the type of diff:

  • @ - Line numbers on left and right hand side.
  • " " (space) - Context, left and right hand side are equal.
  • - - Line is in left hand side, but not in right hand side.
  • + - Line is in right hand side, but not in left hand side.


This example computes the diff between the given tables.

select apex_string_util.diff (
           p_left  => apex_t_varchar2('how','now','brown','cow'),
           p_right => apex_t_varchar2('what','now','brown','cow',1,2,3) )
  from sys.dual;

-> apex_t_varchar2 (
       '@@ 1,0 @@',
       '@@ 1,1 @@',
       ' now',
       ' brown',
       ' cow',
       '@@ 4,5 @@',
       '+3' )