数值函数
求绝对值
Select abs(-1) from dual
进一法
select ceil(12.1) from dual
去尾法
select floor(12.6) from dual
四舍五入
select round(12.4) from dual
四舍五入保留2..n位小数
select round(12.4123,2) from dual
数字截取
默认截取整数
select trunc(123.12) from dual
截取小数后几位
select trunc(123.12,1) from dual
截取小数前几位
select trunc(123.12,-1)from dual
字符函数
转换成大写
select upper('s') from dual
转换成小写
select lower('S') from dual
去掉空格(有时间空格的问题很坑)
select trim(' as ') from dual
去掉左边空格
select ltrim(' as') from dual
select rtrim('as ') from dual
去掉左边指定的字符
select ltrim('abcdec','ab') from dual
去掉右边指定的字符
select rtrim('abcdec','c') from dual
替换函数
select replace('as','s','q') from dual
字符串相加
select 'aa'||'bb' from dual
select concat('aa','bb') from dual
截取字符串的函数
select substr('abcde',1,3)
from dual
求长度的函数
select length('as') from dual
转换函数
转化成数字
select to_number('123') from dual
转化成字符串
select to_char(123) from dual
*转化成字符串,格式化时间
select to_date(sysdate) from dual
来个完整年月日时分秒的时间
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual
时间24小时制
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual
处理Null的函数
*为空返回制定的代替,不为空返回自己
select nvl('','b') from dual
*不为空返回参数2为空返回参数3
select nvl2('','b','c') from dual
Oracle 自定义函数
函数必须要有一个返回值
Oracle 存储过程
优点:
1、 存储过程预编译SQL语句,编译一次后面执行不需要再编译
执行效率快一点
2、可以再存储过程进行SQL编码,可以减小服务器压力
缺点:
1、代码量多,难以维护
打开缓存
Set Serveroutput on
创建存储过程
Create procedure 存储名
As
Begin
Dbms_output.put_line();-–输出
End;
执行存储过程
Beign
存储过程名;
End;
declare pr int;
begin
proc_ddd(1,2,pr);
Dbms_output.put_line(pr);
end;
系统函数
最新推荐文章于 2024-07-18 14:34:06 发布