title: How to eliminate duplicates from multiple LISTAGG 'ed columns in Oracle
body: <p>What is the logic I am missing to eliminate duplicate values from listagg function in following script.?</p>
  
  <p>The following the sys.privs table:</p>
  
  <pre><code>SQL&gt; desc sys.privs
   Name                                      Null?    Type
   ----------------------------------------- -------- ----------------------------
   GRANTEE                                            VARCHAR2(30 CHAR)
   GRANTED_ROLE                              NOT NULL VARCHAR2(30)
   PRIVILEGE                                 NOT NULL VARCHAR2(40)
   OWNER                                     NOT NULL VARCHAR2(30)
   TABLE_NAME                                NOT NULL VARCHAR2(30)
  </code></pre>
  
  <p>The following is the script </p>
  
  <pre><code>SELECT grantee,
       LISTAGG(granted_role, '-') WITHIN GROUP (ORDER BY granted_role) AS granted_role,
       LISTAGG(privilege, '-') WITHIN GROUP (ORDER BY privilege) AS privs,
       owner,
       table_name
  FROM (
       SELECT UNIQUE
              grantee,
              granted_role,
              privilege,
              owner,
              table_name
         FROM sys.privs
       )
  GROUP BY grantee, owner, table_name;
  </code></pre>