数据库常用函数
1.将几个字段连成一个字段:||
示例:select last_name||','||job_id "employee and title" from employees
2.在xx区间:between,not between
示例:select last_name from employees where salary not between 5000 and 12000
3.查找字段包含某个字母
示例1,含有某个字母:select last_name from employees where last_name like '%a%'
示例2,第三个字母 :where last_name like '__a%'
4.将查询的属性首字母变大写:initcap
示例:select initcap(last_name) "name" from employees
5.查询某个属性字符串长度:length
select length(last_name) "length" from employees
6.日期操作
6.1 当前日期
示例:select sysdate as date from dual
6.2日期相减差的月份: MONTHS_BETWEEN (date1, date2),前减后
示例:select round ((moths_between(sysdate,hire_date)),0)as months from employees
6.3 显示星期几
示例:select to_char(hire_date,'day') day from employees
7.填充函数:lapad,rpad
7.1 lpad( string1, padded_length, [ pad_string ] )
其中string1是需要粘贴字符的字符串 padded_length是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成padded_length; pad_string是个可选参数,这个字符串是要粘贴到string1的左边
示例:select lpad(salary,15,'$')as salary from employees
8 对空值做操作:NVL
示例:select nvl(to_char(commision_pct),'no commission') comm from employees