oracle - 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;
解决方案
推荐阅读
- node.js - 尝试运行 angular-fullstack 客户端样板时出错
- python-3.x - 从文本文件中搜索单词列表并使用 python 打印前三行
- linux - 包 mesa-filesystem 向后兼容
- mongodb - 您可以在“_id”中包含一个计数字段吗?
- google-apps-script - 有没有自动合并相邻单元格的脚本?
- python - 如何在元组数组中找到特定的元组?
- clojure - 如何重写 core.logic 片段?
- scala - 为什么用磨机运行 ZIO 应用程序不起作用?
- android - 如何检测Android中的最大USB电流?
- apache-flink - 使用 Flink SQL API 处理事件