outputRow()

After each call to the processRow() method, if the outputRow() method is defined, it is called until it returns null. This allows a UDTF to output any number of rows efficiently.

The outputRow() method is always called with a single parameter, which is the number of times outputRow() has been called since the processRow() method was called.

Here is an example of using outputRow() in combination with processRow(). The processRow() method is called first and stores the value of x in the rows_to_output variable. The database then calls the outputRow() method until it returns null. On the first call, the rownum argument will have the value 1, the second call it will have the value 2, etc.

function processRow(x)
    rows_to_output = x
    return null
end

function outputRow(rownum)
    if rownum > rows_to_output then 
        return null 
    end
    return { rownum }
end

After the outputRow() method has returned null, the database will then call the processRow() method again with the next row of data to be processed. The outputRow() method must return data in exactly the same format as is allowed for the processRow() method.

Even if the processRow() method returns a result, the outputRow() method will still be called after each call to processRow(). For example:

function processRow(x)
    rows_to_output = x
    return { 0 }
end

function outputRow(rownum)
    if rownum > rows_to_output then
        return null
    end
    return { rownum }
end