--全部小写 全部大写 全部首字母大写
select lower('ATGUIGUJAVA'),UPPER('ATGUIGU Java'),initcap('ATGUIGU Java')
from dual
--
运行结果
--转换为小写查询
select * from employees
where lower(last_name)='king'
运行结果
字符控制函数
--拼接 截取 长度
select
CONCAT('hello','world'), SUBSTR('helloworld',2,4), LENGTH('helloworld')
from dual;
运行结果
--判断字符的位置 没有返回0
select instr('helloworld','w') from dual
运行结果
--座对齐 输出十位 不足*号补齐 左端补齐
select employee_id,last_name,lpad(salary,10,'*') from employees;
运行结果
--在字符里面取出 去除首尾h
select trim('h'from 'hhellhoworldh') from dual
运行结果
--替换所有的a
select replace('abcgavc','a','c') from dual
运行结果
--保留数
select round(435.35,2),round(435.35),round(435.35,-2) from dual
运行结果
--保留数 截断
select trunc(435.35,2),trunc(435.35),trunc(435.35,-2) from dual
运行结果
--员工工作天数
select employee_id,last_name,trunc(sysdate-hire_date) worked_days
from employees;
运行结果
--员工工作月数
select employee_id,last_name,(sysdate-hire_date)/30,months_between(sysdate,hire_date)
from employees;
运行结果
--加上月数2月 减去三月 下个周日
select add_months(sysdate,2),add_months(sysdate,-3),next_day(sysdate,'星期日')
from dual
运行结果
--每个月倒数第二天来的员工
select last_name,hire_date from employees where hire_date=last_day(hire_date)-1
运行结果
--日期函数 按照月份 日期
select round(sysdate,'month'),round(sysdate,'mm'),trunc(sysdate,'hh')
from dual
运行结果
隐式类型转换
--转换
select '12'+2 from dual;
运行结果
显式转换
--进行日期转换
select employee_id,hire_date from employees
--where hire_date='7-06月-94'
where to_char(hire_date,'yyyy-mm-dd')='1994-06-07'
运行结果
--进行日期转换
select employee_id, to_char(hire_date,'yyyy"年"mm"月"dd"日"') from employees
--where hire_date='7-06月-94'
where to_char(hire_date,'yyyy"年"mm"月"dd"日"')='1994年06月07日'
运行结果
--转换
select to_char(1234567.89,'999,999,999,99') from dual;
运行结果
--员工工资
select to_char(1234567.89,'$999,999,999,99') from dual;
员工工资