查找所有子分区名称

Find all Subpartition name

Table 已根据值可以为“1”或“2”的列 (INSTANCE) 进行了子分区。想要列出所有包含 INSTANCE 值为 '2'

的子分区名称
select * from user_tab_subpartitions sp where table_name='TEST' and sp.NUM_ROWS >0
and to_char(HIGH_VALUE)='2';

错误

ORA-00932: inconsistent datatypes: expected CHAR got LONG

HIGH_VALUE 是 LONG()

类型

您可以通过具有该值的记录的rowids 获取包含特定值的所有子分区。

试试这个查询:

select distinct subobject_name
from user_objects obj join TEST tbl on obj.object_name = 'TEST' 
 and dbms_rowid.rowid_object(tbl.rowid) = obj.data_object_id 
where tbl.INSTANCE = 2;
set serveroutput on;

DECLARE
 high_val VARCHAR2(32767); 
BEGIN
FOR rec IN (select PARTITION_NAME,SUBPARTITION_NAME,HIGH_VALUE  from user_tab_subpartitions sp where table_name='TEST' and sp.NUM_ROWS >0) LOOP
  high_val := rec.HIGH_VALUE;
  IF high_val LIKE '2%' THEN 
    dbms_output.put_line(rec.SUBPARTITION_NAME);
  END IF;
END LOOP;
END;