首页 > 解决方案 > Oracle 循环 - 声明

问题描述

我想使用 LOOP 遍历表中的所有分区来更改每个分区的一些数据。我开始喜欢:

BEGIN
FOR n in (here is the select statement which chooses the partition names)
LOOP
UPDATE table_name    
PARTITION (n)
SET
here are columns to change with new values;
COMMIT;
END LOOP;
END;

我收到错误 ORA 02149 和 ORA 06512 分区不存在。它与某些声明有关吗?我应该怎么解决?

标签: oracleloopsplsqlpartition

解决方案


您可以将数据字典视图一起execute immediate用作user_tab_partitions

Begin
  for c in ( select * 
               from user_tab_partitions p 
              where p.table_name = 'TABLE_NAME' 
              order by p.partition_position )
  loop
    execute immediate 'update '||c.table_name||' partition('||c.partition_name||') 
                          set col1 = ''xYz'' ';
    commit;
  end loop;
End;

推荐阅读