實用技巧

--字符串表達是求值

WITH T AS
( SELECT '1+2+3+4' express FROM DUAL
   UNION ALL
   SELECT '21+2+32+4'  FROM DUAL
   UNION ALL
   SELECT '41+22+13+4' FROM DUAL
  )
SELECT dbms_aw.eval_number(express ) FROM T


--提取字段中的數字信息
select t20,translate(t20,'1234567890.'||t20,'1234567890.') as "保留數字"   from macc.lmf_1402 where t20 is not null 


length(translate(bill_id,'abcdefghijklmnopqrstuvwxyz.'||bill_id,'abcdefghijklmnopqrstuvwxyz.'))>0

--for update 引發 scn 值跳躍增長 bug 解決辦法
select t.* , rowid from table_name t 
替代
select ...  for update 


--
SELECT * FROM t_sys_dept where dept_status in (0,1)  START WITH dept_parent_id =10 CONNECT BY PRIOR  dept_id=dept_parent_id



--指定某個菜單下全部報表訪問記清單
select b.menu_id,c.menu_name,a.rpt_id,d.rpt_name,a.view_oper_name,a.view_oper_date,a.view_ip
from mz_user.ls_rpt_view_log a,
     mz_user.ls_rpt_menu_link b,
     mz_user.t_sys_menu c,
     mz_user.ls_rpt_design d
where b.rpt_id=a.rpt_id(+)  
  and a.rpt_id=d.id   
  and b.menu_id=c.menu_id
  and c.menu_status=1
  and b.menu_id in (select menu_id FROM mz_user.t_sys_menu a
  START WITH menu_id=5000108431 CONNECT BY PRIOR  menu_id=menu_parent_id and menu_status=1)


--oracle 隨即更新時間而且控制必定的範圍
update t set timestamp=timestamp + to_number(to_date('20130701', 'YYYYMMDD') - trunc(to_date(to_char( timestamp,'YYYYMMDD'),'YYYYMMDD') - DBMS_RANDOM.VALUE(1,180),'DD'))

以上是更新時間控制在 201307-201312 期間


中位值
median(column)



--角色對應菜單矩陣

select distinct *from (
select role_name,
                 decode(count(distinct 縣市業務統計)over(partition by role_name),1,'×',0,'×','') 縣市業務統計,
                 decode(count(distinct 登錄日誌 )over(partition by role_name),1,'×',0,'×','') 登錄日誌 ,
                 decode(count(distinct 用戶管理 )over(partition by role_name),1,'×',0,'×','') 用戶管理 ,
                 decode(count(distinct 角色管理 )over(partition by role_name),1,'×',0,'×','') 角色管理 ,
                 decode(count(distinct 營業統計 )over(partition by role_name),1,'×',0,'×','') 營業統計 ,
                 decode(count(distinct 業務統計 )over(partition by role_name),1,'×',0,'×','') 業務統計 ,
                 decode(count(distinct 取號清單 )over(partition by role_name),1,'×',0,'×','') 取號清單 ,
                 decode(count(distinct 營業窗口統計)over(partition by role_name),1,'×',0,'×','') 營業窗口統計,
                 decode(count(distinct 營業業務統計)over(partition by role_name),1,'×',0,'×','') 營業業務統計,
                 decode(count(distinct 部門管理 )over(partition by role_name),1,'×',0,'×','') 部門管理 ,
                 decode(count(distinct 縣市統計 )over(partition by role_name),1,'×',0,'×','') 縣市統計 ,
                 decode(count(distinct 營業時段統計)over(partition by role_name),1,'×',0,'×','') 營業時段統計
                 
from (
select b.role_name,
case when a.menu_name = '縣市業務統計' then '' else '×' end as 縣市業務統計,
case when a.menu_name = '登錄日誌' then '' else '×' end as 登錄日誌 ,
case when a.menu_name = '用戶管理' then '' else '×' end as 用戶管理 ,
case when a.menu_name = '角色管理' then '' else '×' end as 角色管理 ,
case when a.menu_name = '營業統計' then '' else '×' end as 營業統計 ,
case when a.menu_name = '業務統計' then '' else '×' end as 業務統計 ,
case when a.menu_name = '取號清單' then '' else '×' end as 取號清單 ,
case when a.menu_name = '營業窗口統計' then '' else '×' end as 營業窗口統計,
case when a.menu_name = '營業業務統計' then '' else '×' end as 營業業務統計,
case when a.menu_name = '部門管理' then '' else '×' end as 部門管理 ,
case when a.menu_name = '縣市統計' then '' else '×' end as 縣市統計 ,
case when a.menu_name = '營業時段統計' then '' else '×' end as 營業時段統計
  from t_sys_role b,t_sys_menu a ,t_sys_role_menu c
where c.rm_menu_id = a.menu_id
and b.role_id = c.rm_role_id
group by b.role_name, a.menu_name))
 
相關文章
相關標籤/搜索