Oracle get DISTINCT numeric with a CLOB in the query

前端 未结 1 1151
栀梦
栀梦 2021-01-23 13:11

EDIT: I am looking for a DISTINCT NUMERIC while including a CLOB within the query.

I have two relations.

Relation One:

<         


        
相关标签:
1条回答
  • 2021-01-23 13:43

    If you hash the clob, you can use it in a subquery to grab the max rowid for each eventid_nbr with the same clob hash value. Then you just filter your relation_two table in the where clause.

    SELECT EVENTID_NBR, INPUT_ARGS 
    
    FROM RELATION_ONE, RELATION_TWO 
    
    WHERE RELATION_ONE.LOGID_NBR = RELATION_TWO.LOGID_NBR AND 
      EVENTID_NBR BETWEEN 143 AND 192 AND 
      EVENTID_NBR != 172 AND SYSDATE - 7 >= RELATION_ONE.LAST_UPDATED
    
      AND (RELATION_TWO.EVENTID_NBR, RELATION_TWO.ROWID) IN
          (SELECT DISTINCT EVENTID_NBR,
           MAX(ROWID) OVER (PARTITION BY EVENTID_NBR, DBMS_HASH(INPUT_ARGS,3))
           FROM RELATION_TWO);
    

    The 3 in the HASH specified SHA, but you can also use MD4 (1) or MD5 (2) if you like.

    I'm thinking this could be very slow if you have a lot of rows in the RELATION_TWO table and I'm sure this can be written to perform better, but the concept is sound.

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