39.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.

Syntax

APEX_STRING_UTIL.FUNCTION DIFF (
    p_left    IN wwv_flow_t_varchar2,
    p_right   IN wwv_flow_t_varchar2,
    p_context IN PLS_INTEGER DEFAULT 3 )
    RETURN wwv_flow_t_varchar2;

Parameters

Table 39-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).

Returns

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.

Example

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 @@',
       '-how',
       '@@ 1,1 @@',
       '+what',
       ' now',
       ' brown',
       ' cow',
       '@@ 4,5 @@',
       '+1',
       '+2',
       '+3' )