Oracle常用方法

oracle常用函数整理

时间转换 to_char to_date

select to_char( sysdate, 'yyyy-mm') FROM dual; -- 2014-05
select to_date('2013-01-01 00-00-00','yyyy-mm-dd hh24:mi:ss') from dual; 

md5加密

select md5('123456' ) from dual;
select SUBSTR (md5 ('123456'), 9, 16) from dual;

条件判断 decode

语法: decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)
在sql server/mysql 中等同于下面写法:

IF 条件=值1 THEN
    RETURN(翻译值1)
ELSIF 条件=值2 THEN
    RETURN(翻译值2)
    ......
ELSIF 条件=值n THEN
    RETURN(翻译值n)
ELSE
    RETURN(缺省值)
END IF

根据关键词查询引用reference

select *
from user_source
where lower(text) like '%some_key_words%';

分析计算表

ANALYZE TABLE tbclientinfo COMPUTE statistics;

Oracle设定作业job

DECLARE
    v_job NUMBER;
BEGIN
    dbms_job.submit(v_job, 'pr_tbclient_payuser_stat(trunc(SYSDATE));', trunc(SYSDATE), 'trunc(sysdate)+1+3/24');
    COMMIT;
END;

oralce查询用户作业

select * from user_jobs;

oracle 查询分区表的行数,使用情况等信息

SELECT * FROM user_tab_partitions;

oracle pl/sql 行转列

select typedesc, sum(decode (snapshotdate,date'2014-03-26' ,cnt,0))d26
,sum (decode(snapshotdate, date'2014-03-27',cnt, 0))d27
,sum (decode(snapshotdate, date'2014-03-28',cnt, 0))d28
,sum (decode(snapshotdate, date'2014-03-29',cnt, 0))d29
,sum (decode(snapshotdate, date'2014-03-30',cnt, 0))d30
,sum (decode(snapshotdate, date'2014-03-31',cnt, 0))d31
,sum (decode(snapshotdate, date'2014-04-01',cnt, 0))d01
from (
select snapshotdate,typedesc, sum(cnt) cnt from stuserdevicestats t where typedesc like '%qd%'
and t.snapshotdate>= date'2014-03-26'
group by snapshotdate,typedesc) group by  typedesc;
posted on 2014-05-13 18:04  Frank.Fan  阅读(1364)  评论(0编辑  收藏  举报