首页 > 代码库 > 单行函数

单行函数

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‘)

 

单行函数