oracle函数,查询,事务

函数包括:单行函数,多行函数(分组函数)

数值函数:

--绝对值
select abs(-12.3) from dual;
--向上取值
select ceil(5.3) from dual;
--向下取值
select floor(5.3 )from dual;
--四舍五入
select round(123.4124,2)from dual;
-- 截取小数点之后
select trunc(4252.04524,2) from dual;
--次方
select power(2,3) from dual;
--取余数
select mod(12.11,4) from dual;
--开方
select sqrt(9) from dual;
--判断正负  1为正 -1为负 0为0
select sign(-12) from dual;
View Code

字符函数:

lower(char)  将字符串转换为小写格式

upper(char)  将字符串转换为大写格式

length(char)返回字符串的长度

ltrim(char [,set]) 去掉set左端的字符串

select ltrim('this','th') from dual
View Code
--截取字符
select substr('hehe',3,2) from dual;
--合并
select concat('h','e') from dual;
--查找位置
select instr('he','h') from dual;
--替换
select replace('he','e','h') from dual;
View Code

转换函数:

to_number() 转换为数字

select to_number('2000.02','999999D99') from dual;

to_char()将日期型转变为字符串

select to_char(sysdate,'yyyy-mm-dd') from dual;

to_date()转换为date类型

select to_date('2013-04-05','yyyy-mm-dd') from dual;

nvl(expr1,expr2) 将null转换为实际值

nvl2(expr1,expr2,expr3) 如果expr1不为null 这返回expr2,否则返回expr3

多表查询:

union :返回不重复行

union all:返回所有行

intersect :两个查询都检索到的行

minus:返回第一个查询检索到的行减去第二个查询检索到的行所剩余的行

事务:

commit:提交事务

rollback:回滚事务

savepoint a:设置保存点 整个事务部回滚

rollack to a :取消部分事务

rollack :取消全部事务

存储过程:

-- 4  部门名称和工资
create or replace procedure proc_sal(empo number)
as
Ename varchar2(30);
Sal number;
begin
    select scott.emp.job,scott.emp.sal into Ename,Sal from scott.emp where scott.emp.empno=empo;
    dbms_output.put_line(Ename|| ' '||Sal );
  end;
  begin
   proc_sal(7369);
   end;
View Code

  

原文地址:https://www.cnblogs.com/shuaif/p/3494941.html