PL SQL: group by, drop NULL, drop duplicates, save to list

Viewed 36

I need to do something like:

def first_items(x: pd.Series):
    """Helper function for items those aren't NA."""
    arr = x.values
    arr = np.unique(arr[~pd.isna(arr)])
    if not len(arr):
        return np.nan
    elif len(arr) == 1:
        return arr[0]
    else:
        return arr

tmp.groupby(groups).agg(first_items)

I am interested in doing that in PL SQL. How can I do that?

1 Answers

If you mean you want to take an array named, say, 'strings' containing:

'A', 'B', '', 'A', 'C', ''

and you want to deduplicate it and remove empty values to leave

'A', 'B', 'C'

then the PL/SQL syntax for that would be:

strings := set(strings) multiset except stringtab('', null);

dbFiddle

If you mean something else, then please provide sample data and expected results.

Related