Thứ Ba, 1 tháng 12, 2020

Tạo view nhiều bảng trong Oracle Database

DROP VIEW user1.V_table1;

/* Formatted on 17/06/2013 09:02:28 (QP5 v5.163.1008.3004) */
CREATE OR REPLACE FORCE VIEW user1.V_table1
Sửa bài viết

Script rebuild index theo ngày, tháng, năm trong Oracle Database

---index theo nam
DECLARE
   v_nam          varchar2(4) := '2012';
   v_tablespace   varchar2(50):='INDX';
   cursor c1 is  
--     select table_owner,table_name,max(partition_name)
--     from dba_tab_partitions group by table_owner,table_name having max(partition_name) like '%'||v_nam||'%' and length(max(partition_name))<9;
     select table_owner,table_name,max(partition_name)
     from dba_tab_partitions where table_name='table1' group by table_owner,table_name;
Sửa bài viết

Quản lý Index Partition trong Oracle Database

--1.CHECK
select a.* from DBA_PART_INDEXES a, DBA_TAB_PARTITIONS b where a.owner=B.TABLE_OWNER and a.table_name=B.TABLE_NAME and a.owner not like 'SYS%' and b.partition_name like '%20131231';

-- Script rebuild index partititon unusable
select 'alter index ' || index_owner || '.' || index_name || ' rebuild partition ' || partition_name || ' tablespace INDX nologging parallel 8 online;' from dba_ind_partitions where status='UNUSABLE';


-- Script rebuild các partition index 
--+ Bước 1: Rebuild
select 'alter index ' || index_owner || '.' || index_name || ' rebuild partition ' || partition_name || ' tablespace INDX' ||substr(partition_name,5,4)||' nologging parallel 8 online;' from dba_ind_partitions where 
index_owner='APP_OWNER'
and index_name in (
'index_name_1',
'index_name_2'
)
order by partition_name desc
;
--+ Bước 2: Nologging noparallel
alter index app_owner.index_name_1 noparallel nologging;
alter index app_owner.index_name_2 noparallel nologging;

Sửa bài viết

Thử nghiệm index chạy chậm hơn quét FULL trong Oracle Database

Mục đích: Demo cho các bạn full chậm hơn index, nên dùng index phải rất chuẩn (3-5% giá trị trả về thôi nhé).
Sửa bài viết

Tạo virtual index trong Oracle Database

CREATE TABLE objects_tab AS SELECT * FROM all_objects;

ALTER TABLE objects_tab ADD (
  CONSTRAINT objects_tab_pk PRIMARY KEY (object_id)
);
Sửa bài viết

Tạo virtual index trong Oracle Database

CREATE TABLE objects_tab AS SELECT * FROM all_objects;

ALTER TABLE objects_tab ADD (
  CONSTRAINT objects_tab_pk PRIMARY KEY (object_id)
);
Sửa bài viết

Chuyển bảng non-partition sang partition theo tháng trong Oracle Database

-- Thu tuc chuyen bang user1.table1 partition theo bdate sang partition theo thang
--1.CHECK, lay bang partition
select * from dba_tab_partitions where length(partition_name)=10;

--Lay cau truc bang sau ra lam mau
user1    table1
Sửa bài viết

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master