Stored procedure input as partition name not working in oracle

时间:2016-07-11 19:46:19

标签: sql oracle stored-procedures partitioning database-partitioning

This is my stored procedure and input is the partition name to be exchanged. However, the query cannot recognize my input name ('DATA_EXCHANGE_PAYLOAD_20160630') but this partition did exist in the database.

    CREATE
        OR REPLACE PROCEDURE exchange_partitions (partition_name IN VARCHAR2) AS

    BEGIN
        EXECUTE IMMEDIATE 
    '

    ALTER TABLE BUCLM_ADAPTERDB.DATA_EXCHANGE_PAYLOAD EXCHANGE PARTITION partition_name
        WITH TABLE BUCLM_ADAPTERDB.DATA_EXCHANGE_PAYLOAD_TEMP
    ';
    END;

    exec exchange_partitions('DATA_EXCHANGE_PAYLOAD_20160630');

2 个答案:

答案 0 :(得分:2)

Your partition_name parameter is not being used. The alter table statement is literally looking for the string partition_name. This is not what you want.

To fix it, concatenate the value of partition_name into the dynamic SQL using the concatenation operator ||:

CREATE OR REPLACE PROCEDURE exchange_partitions (partition_name IN VARCHAR2) AS
BEGIN
    EXECUTE IMMEDIATE 'ALTER TABLE BUCLM_ADAPTERDB.DATA_EXCHANGE_PAYLOAD
                       EXCHANGE PARTITION ' || partition_name || ' WITH
                       TABLE BUCLM_ADAPTERDB.DATA_EXCHANGE_PAYLOAD_TEMP';
END;

答案 1 :(得分:-1)

EXECUTE IMMEDIATE  'ALTER TABLE BUCLM_ADAPTERDB.DATA_EXCHANGE_PAYLOAD 
                    EXCHANGE PARTITION :1  WITH TABLE 
                    BUCLM_ADAPTERDB.DATA_EXCHANGE_PAYLOAD_TEMP'
                    USING partition_name;