Home > Database > Mysql Tutorial > body text

Oracle内联视图更新遇到的问题

WBOY
Release: 2016-06-07 14:54:21
Original
1761 people have browsed it

遇到一个批量更新的需求,我打算用内联视图更新+where in list的技巧处理。

遇到一个批量更新的需求,我打算用内联视图更新+where in list的技巧处理。

UPDATE (

SELECT /*+ BYPASS_UJVC */ *
    FROM mvbox_space.music_original t1
        INNER JOIN (
            SELECT REGEXP_SUBSTR(value_str, '[^,]+', 1, 1) AS p1, REGEXP_SUBSTR(value_str, '[^,]+', 1, 2) AS p2
            FROM (
                SELECT SUBSTR(inlist, INSTR(inlist, ';', 1, LEVEL) + 1, INSTR(inlist, ';', 1, LEVEL + 1) - INSTR(inlist, ';', 1, LEVEL) - 1) AS value_str, level AS l
                FROM (
                    SELECT ';' || '20077,1;20078,2' || ';' AS inlist
                    FROM DUAL
                )
                CONNECT BY LEVEL             )
        ) t2 ON t1.opus_id = t2.p1
)
SET visit_num = nvl(visit_num, 0) + p2, total_today = nvl(total_today, 0) + p2, total_this_week = nvl(total_this_week, 0) + p2, total_this_month = nvl(total_this_month, 0) + p2

在测试库10.2.0.1通过.
    但是拿到线上10.2.0.4,居然报错,这个内部的HINT没有生效.
    后来改写为

MERGE INTO mvbox_space.music_original t1

USING (
    SELECT REGEXP_SUBSTR(value_str, '[^,]+', 1, 1) AS p1, REGEXP_SUBSTR(value_str, '[^,]+', 1, 2) AS p2
    FROM (
        SELECT SUBSTR(inlist, INSTR(inlist, ';', 1, LEVEL) + 1, INSTR(inlist, ';', 1, LEVEL + 1) - INSTR(inlist, ';', 1, LEVEL) - 1) AS value_str, LEVEL AS l
        FROM (
            SELECT ';' || '20077,1;20078,2' || ';' AS inlist
            FROM DUAL
        )
        CONNECT BY LEVEL     )
) t2 ON t1.opus_id = t2.p1
WHEN MATCHED THEN UPDATE SET t1.visit_num = NVL(t1.visit_num, 0) + t2.p2, t1.total_today = NVL(t1.total_today, 0) + t2.p2, t1.total_this_week = NVL(t1.total_this_week, 0) + t2.p2, t1.total_this_month = NVL(t1.total_this_month, 0) + t2.p2

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template