Oracle 表分区操作,表分区一天为分区创建,表分区数据查询,以及删除表分区数据自动重建索引

表分区创建,按天进行分区。

create table T_REALTIME_GPS_PARTCAR_HIS

(
  id            VARCHAR2(50) default sys_guid() not null,
  devphone      VARCHAR2(50),
  f_car_no      VARCHAR2(32),
  longitude     VARCHAR2(50),
  latitude      VARCHAR2(50),
  send_datetime VARCHAR2(50),
  depcode       VARCHAR2(32),
  personid      VARCHAR2(32),
  depid         VARCHAR2(32),
  sjly          VARCHAR2(10),
  djsj          TIMESTAMP(6) default systimestamp,
  lyid          VARCHAR2(200),
  state         VARCHAR2(1),
  omspersonid   VARCHAR2(32)
)
--一天为单位创建分区
partition by range(djsj)
interval (numtodsinterval(1,'day'))
(
 partition PART_REALTIME190331 values less than (to_date('2019-03-31','yyyy-mm-dd'))
);
-- Add comments to the columns 
comment on column T_REALTIME_GPS_PARTCAR_HIS.devphone
  is '设备SIM卡号';
comment on column T_REALTIME_GPS_PARTCAR_HIS.f_car_no
  is '车牌号';
comment on column T_REALTIME_GPS_PARTCAR_HIS.longitude
  is '经度';
comment on column T_REALTIME_GPS_PARTCAR_HIS.latitude
  is '纬度';
comment on column T_REALTIME_GPS_PARTCAR_HIS.send_datetime
  is '发送时间';
-- Create/Recreate primary, unique and foreign key constraints 
alter table T_REALTIME_GPS_PARTCAR_HIS
  add primary key (ID)
  using index 
  tablespace ZYML
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

Oracle 表分区查询操作,以及删除表分区数据自动重建索引

--查指定分区下数据
SELECT COUNT(*) FROM  T_REALTIME_GPS_PARTCAR_HIS PARTITION(partname);

--查看表分区
select table_name,partition_name from user_tab_partitions where table_name='tablename';

--根据表分区时间查询
SELECT * FROM  T_REALTIME_GPS_PARTCAR_HIS  partition  for(to_date('2019-05-16','yyyy-mm-dd')) t  WHERE t.license_plate_num='鲁AM****' ORDER BY t.send_datetime DESC;

  
--删除分区,数据也自动删除
alter table tableName DROP PARTITION partionName update indexes;  

--只删除数据
alter table tableName TRUNCATE PARTITION partionName;  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章