Rumah >pangkalan data >tutorial mysql >Oracle内联视图更新遇到的问题

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

WBOY
WBOYasal
2016-06-07 14:54:211765semak imbas

遇到一个批量更新的需求,我打算用内联视图更新+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

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn