SQL> select to_date('2014-10-11 12:13:14','yyyy-mm-dd hh:mi:ss') from dual; TO_DATE('2014-10-1112:13:14',' ------------------------------ 2014-10-11 12:13:14
SQL> select trunc(sysdate,'month') from dual; TRUNC(SYSDATE,'MONTH') ---------------------- 2014-11-01
SQL> select trunc(last_day(sysdate)) from dual; TRUNC(LAST_DAY(SYSDATE)) ------------------------ 2014-11-30
SQL> select trunc(sysdate,'year') from dual; TRUNC(SYSDATE,'YEAR') --------------------- 2014-01-01
SQL> select add_months(trunc(sysdate,'year'),12)-1 from dual; ADD_MONTHS(TRUNC(SYSDATE,'YEAR ------------------------------ 2014-12-31
SQL> select cast(to_char(last_day(sysdate),'dd') as int) from dual; CAST(TO_CHAR(LAST_DAY(SYSDATE) --------------------------------------- 30
SQL> select last_day(sysdate)-sysdate from dual; LAST_DAY(SYSDATE)-SYSDATE ------------------------- 8
SQL> select next_day(sysdate,1) from dual; NEXT_DAY(SYSDATE,1) ------------------- 2014-11-23 17:39:48
<pre name="code" class="sql" style="font-size: 14px;">SQL> <span style="font-family: Arial, Helvetica, sans-serif;">select months_between(to_date('2014-11-01','yyyy-mm-dd'),to_date('2014-01-01','yyyy-mm-dd')) from dual;</span>MONTHS_BETWEEN(TO_DATE(‘2014-1------------------------------ 10 2、字符串类函数
SQL> select to_char(sysdate,'yyyy-mm') from dual; TO_CHAR(SYSDATE,'YYYY-MM') -------------------------- 2014-11
SQL> select upper('a') || lower('B') || length('aaa') from dual; UPPER('A')||LOWER('B')||LENGTH ------------------------------ Ab3
SQL> select lpad('aaa',5,'*'),rpad('aaa',5,'*') from dual; LPAD('AAA',5,'*') RPAD('AAA',5,'*') ----------------- ----------------- **aaa aaa**
SQL> select ltrim('abbb','a'),rtrim('1234','4'),trim(' ABC ') from dual; LTRIM('ABBB','A') RTRIM('1234','4') TRIM('ABC') ----------------- ----------------- ----------- bbb 123 ABC
SQL> select substr('abcde',1,2) from dual; SUBSTR('ABCDE',1,2) ------------------- ab
SQL> select instr('abcad','a',1),instr('abcad','a',2,1) from dual; INSTR('ABCAD','A',1) INSTR('ABCAD','A',2,1) -------------------- ---------------------- 1 4
SQL> select round(12.12),round(12.12,1),round(12.12,-1) from dual; ROUND(12.12) ROUND(12.12,1) ROUND(12.12,-1) ------------ -------------- --------------- 12 12.1 10
SQL> select trunc(12.12),trunc(12.12,1),trunc(12.12,-1) from dual; TRUNC(12.12) TRUNC(12.12,1) TRUNC(12.12,-1) ------------ -------------- --------------- 12 12.1 10
SQL> select mod(1,3),ceil(12.56),floor(12.56) from dual; MOD(1,3) CEIL(12.56) FLOOR(12.56) ---------- ----------- ------------ 1 13 124、系统函数sys_context
SQL> select sys_context('userenv','db_name') dbName,sys_context('userenv','nls_date_format') date_fromat from dual; DBNAME DATE_FROMAT -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- orcl DD-MON-RR
原文地址:http://blog.csdn.net/mdcmy/article/details/41176321