---
title: "oracle积累"
author: "wjeye"
date: "2011-09-13T16:18:23Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2012-02-24T13:10:36Z"
id: 1171004
url: "https://wjeye.iteye.com/blog/1171004"
---

1、查询当前用户表 占用的空间大小

   select t.segment\_name,sum(t.bytes)/1024/1024  
 from user\_segments t  
 where segment\_name like 'TB%'  
 group by t.segment\_name  
 order by sum(t.bytes)/1024/1024  desc

2、删除表分区  
   
alter table  TB\_CALL\_CUST\_DAY  drop partition PART\_20110528;（普通分区名称）

alter table TB\_ORDER\_USER\_DAY  drop partition PART\_20110609\_SUBPART\_210001;（子分区名称）

 

3、查询表的子分区(当前数据用户)  
select *  
     from user\_segments t  
    where segment\_name like 'TB\_ORDER\_USER\_DAY%'  
   
 手工增加子分区(分区必须大于当前分区日期)

alter table   tb\_order\_info\_user\_day  add  partition  part\_20111002 values less than ('20111103');

 4、创建表的时候指定表分区  
 create table  test  
    tablespace tbs\_test  
as  
  select  * from    user

 

 

5、alter table 增加多个字段  
 alter table  tb\_cust\_view\_day                                                                                       
 add  (total\_pith\_fee NUMBER(12,2),total\_call\_dur NUMBER(12),total\_send\_sms\_cnt NUMBER(12),total\_gprs\_m NUMBER(17,2)) ;  
                                                                                                                        
删除字段 alter table tb\_cust\_view\_day drop column  total\_pith\_fee   

 

6、单表赋权，如果想把用户A下的table1的update权限赋予用户B  
在用户A连接状态下执行:  
grant update  on   table1 to   B;

grant select on  table1 to  B ; --查询权限

 

grant   select  on   tb\_user\_info\_day  to   user   

 

7、统计一个月的上班时间点（包括周末）

select  
substr(to\_char(t.oper\_time,'yyyymmddhh24miss'),-6)  
from vgopqry.masa\_operation t

where   substr(to\_char(t.oper\_time,'yyyymmddhh24miss'),-6) between '083000'  And '180000'  
 and to\_char(t.oper\_time,'yyyymmdd')  like '201110%'  
\--and to\_char(t.oper\_time,'yyyymmdd')  ='20111030'  
Order By t.f\_time

 

8、截取用户邮箱前缀

 

select  substr(t.email,0,instr(t.email,'@')-1) as  befor\_email  from user\_test t