删除分区表
alter table [表名称] drop partition [分区表的名称] ;
select * from user_tab_partitions d where d.table_name='BMP_CUSTOMER_INTERACTION';
-- user_tab_partitions 当前的用户。所以不用用户table_owner=USER 和 dba_tab_partitions 而它存在授权的问题一般不用这个。这个不同要用table_owner=USER
下面是用来检测是否有分区。如果有就显现出来 我在PL/SQL test Window执行的
SELECT * FROM dba_tab_partitions p WHERE p.table_owner=USER AND p.table_name='BMP_CUSTOMER_INTERACTION' AND p.partition_name='BRAND_ACTOS'
“BMP_CUSTOMER_INTERACTION” 是表的名称一定要大写如果小写‘bmp_customer_interaction’ 检索不到数据的
table_owner=USER 是你的登陆的用
-- Created on 2/17/2011 by ADMINISTRATOR
对下面的对应的三张表进行分区
DECLARE
v_tablespace VARCHAR2(80) := NULL; 表空间
v_brand VARCHAR2(20) := 'ACTOS';-- 品牌的名称 按品牌来分区
v_company VARCHAR2(80) := NULL; 公司的名称
v_sql VARCHAR2(4000) := NULL;
v_count NUMBER := 0;
BEGIN
IF USER = 'BMP' THEN
v_tablespace := 'TABLESPACE BMP_DATA_A';
END IF;
如果没有记录时:
SELECT COUNT(1)
INTO v_count
FROM bmp_brand b
WHERE b.brd_brand = v_brand;
IF v_count > 0
THEN
SELECT b.brd_company
INTO v_company
FROM bmp_brand b
WHERE b.brd_brand = v_brand;
END IF;
v_sql := 'SELECT COUNT(1) FROM user_tab_partitions p WHERE p.table_name=''BMP_CUSTOMER_INTERACTION'' AND p.partition_name=''BRAND_'||v_brand||'''';
dbms_output.put_line(v_sql);
EXECUTE IMMEDIATE (v_sql) INTO v_count;
dbms_output.put_line(v_count);
v_sql := 'ALTER TABLE bmp_customer_interaction SPLIT PARTITION BRAND_DEFAULT VALUES (''' ||
v_brand || ''') INTO (PARTITION BRAND_' || v_brand ||
v_tablespace || ', PARTITION BRAND_DEFAULT' || v_tablespace || ')';
-- 进行判断当前用户是否进行分区,如果有分区的 v_count =1否侧v_count =0;为0进行分区;
IF v_count = 0 THEN
dbms_output.put_line(v_sql);
EXECUTE IMMEDIATE (v_sql);-- 就执行这个语句;
END IF;
v_sql := 'SELECT COUNT(1) FROM user_tab_partitions p WHERE p.table_name=''BMP_TX_RESPONSE'' AND p.partition_name=''BRAND_'||v_brand||'''';
dbms_output.put_line(v_sql);
EXECUTE IMMEDIATE (v_sql) INTO v_count;
v_sql := 'ALTER TABLE bmp_tx_response ADD PARTITION BRAND_' || v_brand ||
' VALUES (''' || v_brand || ''')' || v_tablespace;
dbms_output.put_line(v_sql);
IF v_count = 0 THEN
EXECUTE IMMEDIATE (v_sql);
END IF;
v_sql := 'SELECT COUNT(1) FROM user_tab_partitions p WHERE p.table_name=''BMP_CUSTOMER'' AND p.partition_name=''COMPANY_'||v_company||'''';
dbms_output.put_line(v_sql);
EXECUTE IMMEDIATE (v_sql)INTO v_count;
v_sql := 'ALTER TABLE bmp_customer ADD PARTITION COMPANY_' || v_company ||
' VALUES (''' || v_company || ''')' || v_tablespace;
dbms_output.put_line(v_sql);
IF v_count = 0 THEN
EXECUTE IMMEDIATE (v_sql);
END IF;
END;