Oracle函数整理

时间:2023-03-09 08:26:07
Oracle函数整理
 select abs (-) from dual;--绝对值

 select mod (,) from dual;--取模,取余数

 select ceil (12.1) from dual;--去上限值

 select floor (12.1) from dual;--去下限值

 select round (12.4567,) from dual; -- 四舍五入

 select trunc (12.456,) from dual; -- 截取,不四舍五入

 select trunc (12.456,) from dual; -- 截取,不四舍五入(截整)

 select length ('asddsa') from dual;--字符串长度

 select xingm, length (xingm) from t_hq_ryxx;

 select xingm, substr (xingm,,) from t_hq_ryxx;--截取,(从第一位开始截取,截两位)

 select concat ('sa',concat ('sdsd','ddd')) from dual;

 select 'sa'||'sdsd'||'ddd' from dual;

 --查找字符串

 select instr ('abcdef','d') from dual;

 select instr ('abcdefdf','d',) from dual;

 select instr ('abcdefdf','d',) from dual; --数字指定起始位置

 select instr ('abcdefdf','dd',) from dual; --找不到返回0

 --转换大小写

 select upper ('assa'),lower ('SDDA') from dual;

 select upper ('assa'),lower ('SDDA'), initcap ('this is a car') from dual;  --initcap 首字母转换大写

 select replace ('abcdef','ab','') from dual;    --替换

 update t_hq_ryxx set xingm = replace (xingm,'三','四') where xingm like '三%'

  --填充
select rpad ('aa',, 'c') from dual; select rpad ('aba',, 'de') from dual; select lpad ('aa',, 'rc') from dual; --去空格 select trim (' wfat ') from dual; --去前后空格 select ltrim (' sd1 ') from dual; --去左空格 select rtrim (' sdad ') from dual; --去右空格 --去前缀 select trim (leading 'a' from 'asda') from dual; --前边开始 select trim (trailing 'a' from 'asda') from dual; --右边开始 select trim (both 'a' from 'asda') from dual; --去前后 --日期型函数 select sysdate from dual; select add_months(sysdate,) from dual; --加两个月 select add_months(sysdate,-) from dual; --减两个月 select last_day(sysdate) from dual; select last_day(sysdate) + from dual; --(+)加天数 select last_day(sysdate) - from dual; --(-)减天数 --转换函数 --select cast ('' as number) from dual; --select cast ('' as number) + from dual; --select cast ('' as varchar2()) from dual; --数字长度不能超过字符串长度 --select cast(sysdate as varchar2()) from dual; select to_char(sysdate, 'YYYY-MM-DD')from dual; --日期转换字符串(忽略大小写) select to_char(sysdate, 'yy-mm-dd')from dual; select to_char(sysdate, 'YYYY-DD-MM HH24:mi:ss')from dual; --select to_char(123.456,'9999.9')from dual; select to_date('2015-12-11','yyyy-mm-dd') from dual; --字符串转换日期 select to_number('123.456','9999.999') from dual; select( nianl + gongz) from t_hq_ryxx;