数据仓库服务 GAUSSDB(DWS)-表(Oracle):分区(二)

时间:2024-10-26 11:41:26

分区(二)

在非分区表中,删除表“ALTER TABLE TRUNCATE PARTITION”中的数据。

Oracle语法

迁移后语法

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CREATE TABLE product_list
(
  product_id      VARCHAR2(20),
  Product_Name    VARCHAR2(50),
  Year_Manufacture vARCHAR2(10)
)
partition by list (Year_Manufacture)
( partition PART_2015 VALUES (2011,2012,2013,2014,2015) pctfree 10 initrans 1 ,
 partition PART_2016 VALUES (2016) pctfree 10 initrans 1 ,
 partition PART_2017 VALUES (2017) pctfree 10 initrans 1 ,
 partition PART_2018 VALUES (2018) pctfree 10 initrans 1 ,
 partition PART_2019 VALUES (2019) pctfree 10 initrans 1 ,
 partition PART_2020 VALUES (2020) pctfree 10 initrans 1 ,
 PARTITION PART_unknown VALUES (DEFAULT) );

CREATE OR REPLACE PROCEDURE List_test
IS
V_ID VARCHAR2(10);
BEGIN
 EXECUTE IMMEDIATE 'ALTER TABLE product_list TRUNCATE PARTITION PART_2020;
 NULL;
END;
/

CREATE OR REPLACE PROCEDURE List_test
IS
V_ID VARCHAR2(10);
BEGIN
 EXECUTE IMMEDIATE 'ALTER TABLE product_list TRUNCATE PARTITION PART_' || V_ID;
 NULL;
END;
/
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
CREATE TABLE product_list
(
  product_id      VARCHAR2(20),
  Product_Name    VARCHAR2(50),
  Year_Manufacture vARCHAR2(10)
)
/*partition by list (Year_Manufacture)
( partition PART_2015 VALUES (2011,2012,2013,2014,2015) pctfree 10 initrans 1 ,
 partition PART_2016 VALUES (2016) pctfree 10 initrans 1 ,
 partition PART_2017 VALUES (2017) pctfree 10 initrans 1 ,
 partition PART_2018 VALUES (2018) pctfree 10 initrans 1 ,
 partition PART_2019 VALUES (2019) pctfree 10 initrans 1 ,
 partition PART_2020 VALUES (2020) pctfree 10 initrans 1 ,
 PARTITION PART_unknown VALUES (DEFAULT) )*/;


CREATE OR REPLACE PROCEDURE List_test
IS
V_ID VARCHAR2(10);
BEGIN
 EXECUTE IMMEDIATE 'ALTER TABLE product_list TRUNCATE PARTITION PART_' || V_ID;
 NULL;
END;
/

CREATE OR REPLACE PROCEDURE List_test
IS
V_ID VARCHAR2(10);
BEGIN
 /* EXECUTE IMMEDIATE 'ALTER TABLE product_list TRUNCATE PARTITION PART_' || V_ID; */
 IF 'PART_' || V_ID = 'PART_2015' THEN
    DELETE FROM product_list WHERE Year_Manufacture IN (2011,2012,2013,2014,2015);
 ELSIF 'PART_' || V_ID = 'PART_2016' THEN
    DELETE FROM product_list WHERE Year_Manufacture IN (2016);
 ELSIF 'PART_' || V_ID = 'PART_2017' THEN
    DELETE FROM product_list WHERE Year_Manufacture IN (2017);
 ELSIF 'PART_' || V_ID = 'PART_2018' THEN
    DELETE FROM product_list WHERE Year_Manufacture IN (2018);
 ELSIF 'PART_' || V_ID = 'PART_2019' THEN
    DELETE FROM product_list WHERE Year_Manufacture IN (2019);
 ELSIF 'PART_' || V_ID = 'PART_2020' THEN
    DELETE FROM product_list WHERE Year_Manufacture IN (2020);
 ELSE
    DELETE FROM product_list WHERE Year_Manufacture NOT IN (2011,2012,2013,2014,2015,2016,2017,2018,2019,2020);
 END IF;
 NULL;
END;
/

support.huaweicloud.com/tg-dws/dws_mt_0108.html