我的要求是更新已分区表格的partition_date
列 - MYTABLE
。
我有MYPROC
pl / sql程序来执行此操作。
以下是MYPROC
的相关内容。
p_partition_name VARCHAR2(40);
SELECT distinct(uo.subobject_name)
INTO p_partition_name
FROM MYTABLE t,
user_objects uo
WHERE dbms_rowid.rowid_object(t.rowid) = uo.object_id
AND partition_date BETWEEN '01-OCT-2015' AND '31-OCT-2015';
BEGIN
DBMS_OUTPUT.PUT_LINE('Partition Name' || p_partition_name);
FOR i IN 1 .. partition_table.count
LOOP
UPDATE MYTABLE partition (p_partition_name) SET PARTITION_DATE = '01-AUG-2015' WHERE {..some condition..}
END LOOP;
END;
当我执行MYPROC
时,我得到以下错误。
Error report:
ORA-02149: Specified partition does not exist
ORA-06512: at "NESSDBA.MYPROC", line 116
ORA-06512: at line 2
02149. 00000 - "Specified partition does not exist"
*Cause: Partition not found for the object.
*Action: Retry with correct partition name.
Partition NameSYS_P3495
当我在不使用过程的情况下发出以下普通update
语句并手动传递分区名称时,没有错误。
UPDATE MYTABLE partition (SYS_P3495) SET PARTITION_DATE = '01-AUG-2015' WHERE {..some condition..}
如何将分区名称传递给pl / sql中的更新语句?
答案 0 :(得分:1)
尝试使用动态sql而不是static; 请在下面找到代码,
declare
v_date date:= to_date('01-AUG-2015','dd-mon-yyyy');
bEGIN
FOR i IN (SELECT distinct (uo.subobject_name) partition_name FROM parttab t, user_objects uo
WHERE dbms_rowid.rowid_object(t.rowid) = uo.object_id) LOOP
DBMS_OUTPUT.PUT_LINE('update parttab partition (' || i.partition_name || ') set jdate = '||v_date );
execute immediate 'update parttab partition (' || i.partition_name || ') set jdate = :vv_date' using v_date;
END LOOP;
END;