我有一個表,並有一個分區。如何找到記錄的分區oracle
有16個散列分區是從SUBSCRIBER_01開始..等
表名:SUBSCRIBER
分配柱:CUSTOMER_ID(VARCHAR2 10)
數據庫:11g中
如何能我發現分區的記錄?
Like Customer_ID = 933587
我有一個表,並有一個分區。如何找到記錄的分區oracle
有16個散列分區是從SUBSCRIBER_01開始..等
表名:SUBSCRIBER
分配柱:CUSTOMER_ID(VARCHAR2 10)
數據庫:11g中
如何能我發現分區的記錄?
Like Customer_ID = 933587
我找到了答案。
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;
選擇該行的rowid,並且DBMS_RowID.RowID_Object()
過程將提取數據對象標識。
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
我想你只能找到其中的cust_id = 123 ...分配的分區名稱:
SELECT partition_name, tablespace_name
FROM user_tab_partitions
WHERE table_name = your_table;
試試這個,
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)
我我在這裏使用散列分區。
你可以使用這個腳本:
SELECT L.*, O.SUBOBJECT_NAME
FROM
(
SELECT DBMS_ROWID.ROWID_OBJECT(ROWID) DATA_OBJECT_ID, L.*
FROM YOUR_TABLE L
--WHERE L.ID = 123
) L
JOIN
(
SELECT SUBOBJECT_NAME, DATA_OBJECT_ID
FROM USER_OBJECTS
) O ON O.DATA_OBJECT_ID = L.DATA_OBJECT_ID
;
很慢..... –