首页 > 解决方案 > oracle regexp_like & regexp_count 与变量/表属性

问题描述

在“插入前”的触发器中,我需要检查插入的值是否正常并且是否对应于存储在单独表(parameter_app_source)中的预定义值。这些值存储在属性 delimiting_prefixes 和 delimiting_postfixes 中。如何使用那些可以在 REGEXP_LIKE & regexp_count 中复用的属性?在 substr/instr 中,我可以将它们用作表属性,但不能在 REGEXP_LIKE 和 regexp_count 中使用。目前我尝试使用变量,但效果不佳。当前 delimiting_prefixes 和 delimiting_postfixes 是方括号 [ 和 ],但是它们将来可能会有所不同。

        CREATE OR REPLACE TRIGGER my_trigger BEFORE
        INSERT ON my_table
        FOR EACH ROW
    DECLARE
        lc_parameter_ok          NUMBER;
        lc_delimiting_prefixes   parameter_app_source.delimiting_prefixes%TYPE;
        lc_delimiting_postfixes  parameter_app_source.delimiting_postfixes%TYPE;
        lc_parameter_nok EXCEPTION;
    BEGIN
        WITH first_step AS (
            SELECT DISTINCT
                process_id,
                delimiting_prefixes
                || parameter_name
                || delimiting_postfixes                                               AS parameter_ok,
                delimiting_prefixes,
                delimiting_postfixes
            FROM
                parameter_app_source
        )
        SELECT DISTINCT
            CASE
                WHEN COUNT(*) > 0 THEN
                    1
                ELSE
                    0
            END                           AS lc_parameter_ok,
            MAX(delimiting_prefixes)      AS lc_delimiting_prefixes,
            MAX(delimiting_postfixes)     AS lc_delimiting_postfixes
        INTO
            lc_parameter_ok,
            lc_delimiting_prefixes,
            lc_delimiting_postfixes
        FROM
            first_step a
        WHERE
                a.process_id = :new.rm_prozess_id
            AND ( 
         ( number_pre_postfises = ( regexp_count(:new.infotext_de,'\:lc_delimiting_prefixes') + regexp_count(:new.infotext_de, '\:lc_delimiting_postfixes') )
                AND number_pre_postfises = ( regexp_count(:new.infotext_en, '\:lc_delimiting_prefixes') + regexp_count(:new.infotext_en, '\:lc_delimiting_postfixes') ) )
OR
a.parameter_ok = substr(:new.infotext, instr(:new.infotext, a.delimiting_prefixes), instr(:new.infotext, a.delimiting_postfixes) -(instr(:
            new.infotext, a.delimiting_prefixes) - 1))
                  OR ( NOT REGEXP_LIKE ( :new.infotext,
                                         ':lc_delimiting_prefixes|:lc_delimiting_postfixes',
                                         'i' ) ) );
    
        IF lc_parameter_ok <> 1 THEN
            RAISE lc_parameter_nok;
        END IF;
    EXCEPTION
        WHEN lc_parameter_nok THEN
            raise_application_error(-20201, 'Error detected: either pre or postfixes are missing or they are too many.');
            end;
    END;

标签: oraclevariablesregexp-like

解决方案


推荐阅读