如何找到记录oracle的分区

时间:2012-12-01 13:35:20

标签: database oracle plsql oracle11g database-partitioning

我有一张桌子,上面有一个分区。

有16个散列分区,它从SUBSCRIBER_01等开始。

表名:SUBSCRIBER

分区列:CUSTOMER_ID(VARCHAR2 10)

数据库:11g

如何找到记录的分区?

与Customer_ID = 933587

类似

5 个答案:

答案 0 :(得分:15)

选择行的rowid,DBMS_RowID.RowID_Object()过程将提取数据对象ID。

http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_rowid.htm#i997153

在数据字典中查找该数据对象id并读取subobject_name。

例如:

   SELECT dbms_rowid.rowid_object(ROWID) data_object_id
   FROM INVOICE
   WHERE INVOICE_ID = 2268041139:

   -- data_object_id = 546512

   select * from user_objects where data_object_id = 546512;

   -- SUBOBJECT_NAME = 'PART_P2099_P00'     
   -- OBJECT_TYPE = TABLE PARTITION
   -- OBJECT_ID = 464826
   -- DATA_OBJECT_ID = 546512

答案 1 :(得分:1)

您可以使用此脚本:

body {
    position: relative;
    padding: 30px;
}
div {
    width: 400px;
    height: 200px;
}

div:nth-child(1) {
    border-right: 3px solid #000;
    border-radius: 0px 0px 10px 0px;
    border-bottom: 3px solid #000;
}

div:nth-child(2) {
    border-left: 3px solid #000;
    border-radius: 10px 0 0 0;
    border-top: 3px solid #000;
    position: absolute;
    top: 230px;
    left: 20px;
}

答案 2 :(得分:0)

我认为你只能找到cust_id = 123 ...已分配的分区名称:

SELECT partition_name, tablespace_name
 FROM user_tab_partitions
WHERE table_name = your_table;

答案 3 :(得分:0)

试试这个,

select distinct SUBOBJECT_NAME from user_objects where data_object_id = (SELECT distinct dbms_rowid.rowid_object(ROWID) data_object_id FROM <your table name>   WHERE <your partition key> = <partition key value>and rownum=1)

我在这里使用哈希分区。

答案 4 :(得分:-1)

我找到了答案。

 DECLARE
       pi_partition varchar2(50);
       v_sql        varchar2(250);
       i            number;
       sy          number;
    BEGIN
       FOR i IN 1..16
       LOOP
          IF i < 10 THEN
            pi_partition:= 'SUBSCRIBER_0'||i;
          ELSE
            pi_partition:= 'SUBSCRIBER_'||i;
          END IF;

          sy:=0;
          v_sql:= 'select count(*) into :say from subscriber partition('||pi_partition||') where customer_ID='||''''||'933564'||'''';
          --dbms_output.put_line(pi_partition);
          EXECUTE IMMEDIATE v_sql INTO sa;


          IF sy > 0 THEN

            DBMS_OUTPUT.PUT_LINE('Result: ' || sy||pi_partition);
            EXIT;
          END IF;
       END LOOP;
    END;