我想在过程中使用 ForAll 构造:
现有的 For 循环是:
max_versions constant number := 100;
FOR i IN 1 ..max_vers
LOOP
l_sql := 'update test_table set p' || i ||'= NULL WHERE p' ||i||'=0 AND condition1=' ||n_input1 ||' AND condition3 = ' || n_condition3;
EXECUTE immediate l_sql;
l_sql := 'update test_table set h' || i ||'= NULL WHERE h ||i||'=0 AND condition1=' ||n_input1 ||' AND condition3 = ' || n_condition3;
EXECUTE immediate l_sql;
END LOOP;
这里 max_vers 是一个常数 100,p1...p100 和 h1...h100 是表中的列。如果列的值为 0,则在上面的查询中设置 null。
那么是否可以将 ForAll 与常量而不是集合一起使用?
我尝试过以下操作:首先,我尝试将直接常量与 'Count' 方法一起使用,但因为它是一种收集方法
PROCEDURE Test
IS
TYPE MaxVersTab IS TABLE OF number;
maxvers MaxVersTab := 100;
-- Error1
BEGIN
FORALL i IN 1 .. maxvers .count
EXECUTE IMMEDIATE -- Error2 and Error3
'update test_table set p' || i ||'= NULL WHERE p' ||i||'=0 AND condition1=' ||n_input1 || ' AND condition3 =n_input3' USING maxvers(i);
FORALL i IN 1 .. maxversions.count
EXECUTE IMMEDIATE
'update test_table set p' || i ||'= NULL WHERE p' ||i||'=0 AND condition1=' ||n_input1 || ' AND condition3=n_input3' USING maxvers(i);
我收到如下不同的错误:
- 错误 1) 表达式类型错误
- 错误 2) 语句被忽略
- 错误3)该表达式的类型声明不完整或格式错误
我的问题是,我们可以为 ForAll 中使用的集合(如 100)分配一个范围。请告诉我。
问候