记录我的学习。。。。。。

oracle工作积累

上一篇 / 下一篇  2012-02-24 13:11:55 / 个人分类:oracle

 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  droppartition PART_20110528;(普通分区名称)

alter table TB_ORDER_USER_DAY  drop partitionPART_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');

转移分区

alter table tb_fi_cust_view_day move Partition PART_20100505 tablespace TBS_user nologging;
 
转移表空间 ,将该表20100505的分区转移至表空间TBS_user ,这样他就占用的是user的空间
 
alter table TB_MK_CUST_INFO_DAY drop partition PART_20100301; 删除表分区
 
alter table tbname drop partition partname
 
alter table tbname move partition partname tablespace tbspacename


 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  user_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

9、字母拼接序列
select 'A' || lpad(SEQU_EMP.nextval,10,'0') as aid from dual
结果:A0000008488
 
 
10‘查看长时间操作语句(login as  dba)
 
用到的系统视图:
v$session_longops
v$sqltext
查找长时间操作问题sql的方法
1. select * from v$session_longops a
   where a.ELAPSED_SECONDS>0;
2. select * from v$sqltext a
   where a.ADDRESS= &1_sqladdress
   order by a.PIECE
select elapsed_seconds,opname,target,message,start_time,last_update_time ,v$sqltext.HASH_VALUE,v$sqltext.piece,sql_text
from v$session_longops,v$sqltext
where v$session_longops.SQL_HASH_VALUE=v$sqltext.HASH_VALUE
order by elapsed_seconds desc,v$session_longops.SQL_HASH_VALUE,v$sqltext.piece
 
 
11、列转行
 oracle10g 及以上都可以使用wmsys.wm_concat 此函数
SELECT a.f_userid, wmsys.wm_concat(a.f_roleid) as result
FROM test.user_role a
GROUP BY f_userid
12、 百分比显示0.12%,0.00%
 to_char(100*(NVL(T.SUCESS_ORDER_USER, 0) / nvl(T.ACT_SEND_USER,0)),'fm99999990.00') || '%'

13、树形结构的层级查询
SELECT
  LEVEL,
  t.catalog_id,
  t.catalog_name,
 SYS_CONNECT_BY_PATH(t.catalog_name, '\') AS "FullPath"
FROM
  bi_res_catalog_info t
START WITH
  t.catalog_id IN ('RES')
CONNECT BY PRIORt.catalog_id =parent_catalog_id
ORDER SIBLINGS BYt.catalog_name;

 1 RES 数据 \ 数据
 2 RES002 我的收藏 \数据\我的收藏
 2 RES001 运营报表 \数据\运营报表
 3 RES001027 BOSS运营位统计 \数据\运营报表\BOSS运营位统计
 3 RES001008 系统使用统计报表 \数据\运营报表\系统使用统计报表
 4 RES001016001 2012重点应用 \数据\运营报表\系统使用统计报表\2012重点应用


TAG:

笨笨叶的测试学习窝 引用 删除 wjtest   /   2015-05-21 15:35:34
美式日期转换 to_char(to_date(‘12-jun-15’,'dd-mon-yyyy','nls_date_language=english'),'yyyymmdd')
 

评分:0

我来说两句

Open Toolbar