SELECT DISTINCT CLOB_COLUMN FROM TABLE;

后端 未结 7 834
情书的邮戳
情书的邮戳 2021-01-08 00:08

I would like to find the distinct CLOB values that can assume the column called CLOB_COLUMN (of type CLOB) contained in the table called COPIA.

I have selected a PRO

相关标签:
7条回答
  • 2021-01-08 00:13

    To bypass the oracle error, you have to do something like this :

    SELECT CLOB_COLUMN FROM TABLE COPIA C1 WHERE C1.ID IN (SELECT DISTINCT C2.ID FROM COPIA C2 WHERE ....)

    0 讨论(0)
  • 2021-01-08 00:15

    If truncating the clob to the size of a varchar2 won't work, and you're worried about hash collisions, you can:

    • Add a row number to every row;
    • Use DBMS_lob.compare in a not exists subquery. Exclude duplicates (this means: compare = 0) with a higher rownum.

    For example:

    create table t (
      c1 clob
    );
    
    insert into t values ( 'xxx' );
    insert into t values ( 'xxx' );
    insert into t values ( 'yyy' );
    
    commit;
    
    with rws as (
       select row_number () over ( order by rowid ) rn,
              t.*
       from   t
    )
      select c1 from rws r1
      where  not exists (
        select * from rws r2
        where  dbms_lob.compare ( r1.c1, r2.c1 ) = 0
        and    r1.rn > r2.rn
      );
    
    C1    
    xxx   
    yyy  
    
    0 讨论(0)
  • 2021-01-08 00:21

    add TO_CHAR after distinct keyword to convert CLOB to CHAR

    SELECT DISTINCT TO_CHAR(CLOB_FIELD) from table1;   //This will return distinct values in CLOB_FIELD
    
    0 讨论(0)
  • 2021-01-08 00:24

    You could compare the hashes of the CLOB to determine if they are different:

    SELECT your_clob
      FROM your_table
     WHERE ROWID IN (SELECT MIN(ROWID) 
                       FROM your_table
                      GROUP BY dbms_crypto.HASH(your_clob, dbms_crypto.HASH_SH1))
    

    Edit:

    The HASH function doesn't guarantee that there will be no collision. By design however, it is really unlikely that you will get any collision. Still, if the collision risk (<2^80?) is not acceptable, you could improve the query by comparing (with dbms_lob.compare) the subset of rows that have the same hashes.

    0 讨论(0)
  • 2021-01-08 00:30

    Use this approach. In table profile column content is NCLOB. I added the where clause to reduce the time it takes to run which is high,

    with
      r as (select rownum i, content from profile where package = 'intl'),
      s as (select distinct (select min(i) from r where dbms_lob.compare(r.content, t.content) = 0) min_i from profile t where t.package = 'intl')
    select (select content from r where r.i = s.min_i) content from s
    ;
    

    It is not about to win any prizes for efficiency but should work.

    0 讨论(0)
  • 2021-01-08 00:30

    select distinct DBMS_LOB.substr(column_name, 3000) from table_name;

    0 讨论(0)
提交回复
热议问题