CREATE OR REPLACE PROCEDURE pro_alter_partition(INTERFACE_ID VARCHAR2)
AS
L_partition_name VARCHAR2(100);
L_subpartition_name VARCHAR2(100);
L_subpartition_inc NUMBER;
BEGIN
SELECT MAX(partition_name), MAX(subpartition_name)
INTO L_partition_name, L_subpartition_name
FROM dba_tab_subpartitions
WHERE table_name = UPPER('jcff_int_inb_staging_data');
dbms_output.put_line(L_subpartition_name);
L_subpartition_inc := to_number(substr(L_subpartition_name,9))+1;
L_subpartition_name := substr(L_subpartition_name,1,8)||L_subpartition_inc;
dbms_output.put_line(L_subpartition_inc);
dbms_output.put_line(L_subpartition_name);
EXECUTE IMMEDIATE 'ALTER TABLE JDACUST.JCFF_INT_INB_STAGING_DATA
MODIFY partition '||L_partition_name ||
' ADD subpartition '||L_subpartition_name||' values ('||INTERFACE_ID||')';
END pro_alter_partition;
/
它不应丢弃错误,并且应该更改分区
interface_id是字符串文字。因此,需要用引号包裹。仅因为您使用动态SQL,您需要逃脱它们:
EXECUTE IMMEDIATE 'ALTER TABLE JDACUST.JCFF_INT_INB_STAGING_DATA
MODIFY partition '||L_partition_name ||
' ADD subpartition '||L_subpartition_name||' values ('''||INTERFACE_ID||''')';
动态SQL很难,因为它将编译错误转换为运行时错误。要发现错误,我们需要像编译器一样思考。使自己变得轻松,并使用变量来组装可执行的字符串。您可以禁用变量以查看实际执行的语句,这更容易调试:
stmt := 'ALTER TABLE JDACUST.JCFF_INT_INB_STAGING_DATA
MODIFY partition '||L_partition_name ||
' ADD subpartition '||L_subpartition_name||' values ('''||INTERFACE_ID||''')';
dbms_output.put_line(stmt);
EXECUTE IMMEDIATE stmt;