Drop unused columns--2

本文探讨了在Oracle数据库中,当列被设置为UNUSED状态且列名未知时,如何解决无法执行exchangepartition操作的问题。通过创建表、插入数据、设置列为UNUSED状态以及尝试交换分区等步骤,展示了遇到的错误和解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说明:
如果被设置为UNUSED的列的列名未知的话(比如开发人员已经离职,没有很好的项目管理导致原始表结构丢失,等等。。。),那么这时不能执行exchange partition。
 

04:57:52 SQL>

04:58:47 SQL> create table lunar_test
05:01:05   2  (
05:01:05   3  OBJECT_ID      NUMBER,
05:01:05   4  OWNER          VARCHAR2(30),
05:01:05   5  SUBOBJECT_NAME VARCHAR2(30),
05:01:05   6  OBJECT_NAME    VARCHAR2(128),
05:01:05   7  STATUS         VARCHAR2(7),
05:01:05   8  TIMESTAMP      VARCHAR2(19),
05:01:05   9  CREATED        DATE,
05:01:05  10  GENERATED      VARCHAR2(1),
05:01:05  11  OBJECT_TYPE    VARCHAR2(19)
05:01:05  12  )
05:01:05  13  partition by range (OBJECT_ID)
05:01:05  14  (
05:01:05  15  partition PART_1 values less than ('10000'),
05:01:05  16  partition PART_2 values less than ('20000'),
05:01:05  17  partition PART_3 values less than ('30000'),
05:01:05  18  partition PART_4 values less than ('40000'),
05:01:05  19  partition PART_5 values less than (MAXVALUE)
05:01:05  20  );

Table created.

Elapsed: 00:00:00.17
05:01:06 SQL> insert into  lunar_test(object_id,owner,subobject_name,object_name,status,timestamp,created,object_type)
05:01:12   2  select object_id,owner,subobject_name,object_name,status,timestamp,created,object_type  from dba_objects
05:01:12   3  nologging;

commit;
11467 rows created.

Elapsed: 00:00:00.52
05:01:13 SQL> 05:01:13 SQL>

Commit complete.

Elapsed: 00:00:00.00
05:01:14 SQL> alter table lunar_test set unused column created;
alter table lunar_test set unused column object_type;
Table altered.

Elapsed: 00:00:00.07
05:01:20 SQL>

Table altered.

Elapsed: 00:00:00.05
05:01:22 SQL> select count(*) from lunar_test;

  COUNT(*)
----------
     11467

Elapsed: 00:00:00.02
05:01:48 SQL> alter table lunar_test set unused column created;
alter table lunar_test set unused column created
                                         *
ERROR at line 1:
ORA-00904: "CREATED": invalid identifier


Elapsed: 00:00:00.00
05:03:06 SQL> alter table lunar_test set unused column object_type;
alter table lunar_test set unused column object_type
                                         *
ERROR at line 1:
ORA-00904: "OBJECT_TYPE": invalid identifier


Elapsed: 00:00:00.01
05:03:06 SQL> alter table lunar_test set unused column created;
alter table lunar_test set unused column created
                                         *
ERROR at line 1:
ORA-00904: "CREATED": invalid identifier


Elapsed: 00:00:00.00
05:03:28 SQL> desc lunar_test
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 OBJECT_ID                                          NUMBER
 OWNER                                              VARCHAR2(30)
 SUBOBJECT_NAME                                     VARCHAR2(30)
 OBJECT_NAME                                        VARCHAR2(128)
 STATUS                                             VARCHAR2(7)
 TIMESTAMP                                          VARCHAR2(19)
 GENERATED                                          VARCHAR2(1)

05:03:44 SQL> show user
USER is "LUNAR"
05:03:59 SQL>

05:04:54 SQL> create table lunar_test2
05:05:08   2  (
05:05:08   3  AAA      NUMBER,
05:05:08   4  BBB          VARCHAR2(30),
05:05:08   5  SUBOBJECT_NAME VARCHAR2(30),
05:05:08   6  OBJECT_NAME    VARCHAR2(128),
05:05:08   7  STATUS         VARCHAR2(7),
05:05:08   8  TIMESTAMP      VARCHAR2(19),
05:05:08   9  CREATED        DATE,
05:05:08  10  GENERATED      VARCHAR2(1),
05:05:08  11  OBJECT_TYPE    VARCHAR2(19)
05:05:08  12  )
05:05:08  13  partition by range (OBJECT_ID)
05:05:08  14  (
05:05:08  15  partition PART_1 values less than ('10000'),
05:05:08  16  partition PART_2 values less than ('20000'),
05:05:08  17  partition PART_3 values less than ('30000'),
05:05:08  18  partition PART_4 values less than ('40000'),
05:05:08  19  partition PART_5 values less than (MAXVALUE)
05:05:08  20  );
partition by range (OBJECT_ID)
                    *
ERROR at line 13:
ORA-14030: non-existent partitioning column in CREATE TABLE statement


Elapsed: 00:00:00.02
05:05:10 SQL> create table lunar_test2
05:05:34   2  (
05:05:34   3  AAA      NUMBER,
05:05:35   4  BBB          VARCHAR2(30),
05:05:35   5  SUBOBJECT_NAME VARCHAR2(30),
05:05:35   6  OBJECT_NAME    VARCHAR2(128),
05:05:35   7  STATUS         VARCHAR2(7),
05:05:35   8  TIMESTAMP      VARCHAR2(19),
05:05:35   9  CREATED        DATE,
05:05:35  10  GENERATED      VARCHAR2(1),
05:05:35  11  OBJECT_TYPE    VARCHAR2(19)
05:05:35  12  )
05:05:35  13  partition by range (AAA)
05:05:35  14  (
05:05:35  15  partition PART_1 values less than ('10000'),
05:05:35  16  partition PART_2 values less than ('20000'),
05:05:35  17  partition PART_3 values less than ('30000'),
05:05:35  18  partition PART_4 values less than ('40000'),
05:05:35  19  partition PART_5 values less than (MAXVALUE)
05:05:35  20  );

Table created.

Elapsed: 00:00:00.34
05:05:36 SQL> create table lunar_test_part_2 as select * from lunar_test2 partition(PART_2);

Table created.

Elapsed: 00:00:00.17
05:05:53 SQL> alter table lunar_test_part_2 set unused column aaa;
alter table lunar_test_part_2 set unused column bbb;

Table altered.

Elapsed: 00:00:00.24
05:06:08 SQL>
Table altered.

Elapsed: 00:00:00.15
05:06:08 SQL> alter table lunar_test exchange partition PART_2 with table lunar_test_part_2;
alter table lunar_test exchange partition PART_2 with table lunar_test_part_2
*
ERROR at line 1:
ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION


Elapsed: 00:00:00.02
05:06:13 SQL>

 

但是,我猜应该还是可以从某个地方(数据字典或者某个地方)知道这一列的名字,但是目前还未能测试出来。。。

优化代码 def cluster_format(self, start_time, end_time, save_on=True, data_clean=False, data_name=None): """ local format function is to format data from beihang. :param start_time: :param end_time: :return: """ # 户用簇级数据清洗 if data_clean: unused_index_col = [i for i in self.df.columns if 'Unnamed' in i] self.df.drop(columns=unused_index_col, inplace=True) self.df.drop_duplicates(inplace=True, ignore_index=True) self.df.reset_index(drop=True, inplace=True) dupli_header_lines = np.where(self.df['sendtime'] == 'sendtime')[0] self.df.drop(index=dupli_header_lines, inplace=True) self.df = self.df.apply(pd.to_numeric, errors='ignore') self.df['sendtime'] = pd.to_datetime(self.df['sendtime']) self.df.sort_values(by='sendtime', inplace=True, ignore_index=True) self.df.to_csv(data_name, index=False) # 调用基本格式化处理 self.df = super().format(start_time, end_time) module_number_register = np.unique(self.df['bat_module_num']) # if registered m_num is 0 and not changed, there is no module data if not np.any(module_number_register): logger.logger.warning("No module data!") sys.exit() if 'bat_module_voltage_00' in self.df.columns: volt_ref = 'bat_module_voltage_00' elif 'bat_module_voltage_01' in self.df.columns: volt_ref = 'bat_module_voltage_01' elif 'bat_module_voltage_02' in self.df.columns: volt_ref = 'bat_module_voltage_02' else: logger.logger.warning("No module data!") sys.exit() self.df.dropna(axis=0, subset=[volt_ref], inplace=True) self.df.reset_index(drop=True, inplace=True) self.headers = list(self.df.columns) # time duration of a cluster self.length = len(self.df) if self.length == 0: logger.logger.warning("After cluster data clean, no effective data!") raise ValueError("No effective data after cluster data clean.") self.cluster_stats(save_on) for m in range(self.mod_num): print(self.clusterid, self.mod_num) self.module_list.append(np.unique(self.df[f'bat_module_sn_{str(m).zfill(2)}'].dropna())[0])
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值