1. 程式人生 > >單行函數

單行函數

subst to_date lower 類型 justify substr 姓名 date interval

SQL> select upper(first_name), lower(last_name), length(last_name) from employees;

SQL> select (sysdate-hire_date)/7 from employees;

SQL> select trunc((sysdate-hire_date)/30, 0) from employees;

months_between(sysdate,hire_date)

SQL> select trunc(months_between(sysdate,hire_date), 0) from employees;

SQL> select sysdate+3650 from dual;

SQL> select add_months(sysdate, 120) from dual;

SQL> select next_day(‘2015-09-01‘, ‘friday‘) from dual;

SQL> select next_day(‘2015-10-01‘, 6) from dual;

SQL> select last_day(sysdate) from dual;

SQL> select round(to_date(‘2015-10-10‘,‘yyyy-mm-dd‘), ‘MONTH‘) from dual;

SQL> select round(to_date(‘2015-10-16‘,‘yyyy-mm-dd‘), ‘MONTH‘) from dual;

SQL> select round(to_date(‘2015-10-10‘,‘yyyy-mm-dd‘), ‘YEAR‘) from dual;

SQL> select round(sysdate, ‘DAY‘) from dual;

Interval類型

To_yminterval

To_tsinterval

練習:

找出各月最後三天內受雇的所有雇員

extract(month from hire_date+4) != extract(month from hire_date)

找出早於25年之前受雇的雇員

months_between(sysdate, hire_date)/300>=25

顯示正好為6個字符的雇員姓名

length(last_name)=6

顯示所有雇員的姓名的前三個字符

substr(last_name, 1, 3)

顯示所有雇員的姓名,用a替換所有‘A‘

replace(last_name, ‘A‘, ‘a‘)

單行函數