1

我有两张桌子:Table1Table2Table1有列RECORDID,DATASOURCETYPESTRINGCLOB, 而Table2有 列RECORDID,TIMESTAMPCLICKTYPE. 我编写了一个查询来从STRINGCLOB列中查找 clob XML 字符串“book”,前提是它与给定的 匹配DATASOURCETYPE,如下所示:

SELECT SUBSTR(stringclob, instr(stringclob, 'type>')+5
                        , instr(stringclob,'</type') 
                             - instr(stringclob, 'type>')-5
             ) r_type from Table1
 where DataSourceType = 'Source1'
   AND SUBSTR(stringclob, instr(stringclob,'type>')+5
                        , instr(stringclob, '</type')
                              - instr(stringclob, 'type>')-5
             )
     like '%book%'

现在,我想从上个月(类似于 AND )和 of记录的STRINGCLOB列 ( ) 中查找并计算所有出现的 '%book%' 字符串。我正在努力从两个不同的表中查询数据,知道吗?Table1TIMESTAMP > '01-Nov-12' AND TIMESTAMP < '01-Dec-12'CLICKTYPE <> 'Type1'

确实谢谢

一世。

4

1 回答 1

2

这就是您获得值为 的记录类型的计数的方式book

WITH t
       AS (SELECT   '<?xml version="1.0" encoding="UTF-8"?>
                       <record>
                        <record_number>12345</record_number>
                         <record_type> book </record_type>
                       </record>'
                       STRINGCLOB
             FROM   DUAL
           UNION ALL
           SELECT   '<?xml version="1.0" encoding="UTF-8"?>
                          <record>
                            <record_number>6789</record_number>
                            <record_type> book </record_type>
                         </record>'
                       STRINGCLOB
             FROM   DUAL)
SELECT   COUNT (1) total
  FROM   t
 WHERE   xmltype (t.STRINGCLOB).EXTRACT ('//record_type/text()') LIKE '%book%';

全部的

2

现在,如果你想加入表 2,基于 record_id

 SELECT   COUNT (1) total
   FROM   table1 t1, table2 t2
  WHERE   xmltype (t1.STRINGCLOB).EXTRACT ('//record_type/text()') LIKE
            '%book%'
         AND t1.record_id = t2.record_id
         AND t1.DataSourceType = 'Source1'
         AND (TRUNC (t2.timestamp) > '01-Nov-12'
              AND TRUNC (t2.timestamp) < '01-Dec-12')
         AND t2.clicktype <> 'Type1'
于 2012-12-06T14:44:34.880 回答