只读事务
只读事务是指只允许执行 查询操作,而不允许执行任何的dml(增、删、改)操作的事务。使用只读事务可以确保用户只能取个时刻的数据。
机票代售业务,每天的一个时刻统计今天的销售量,这个就使用只读事务,
设置只读事务以后,尽管其他绘画可能会提交事务,但是只读事务将不再取最新数据的变化,从而保证可以取的特定时间点的数据信息。
设置只读事务
Set transaction read only
SQL函数的使用
字符函数
字符函数式oracle中最长用的函数:
1. lower(char):将字符串转化成小写的格式
2. upper(char): 将字符串转化成大写的格式
3. length(char):返回字符串的长度
4. substr(char,m,n):取字符串的字串
例子
1. 将所有员工的名字按照小写的方式显
select lower(ename) from emp;
2. 将所有员工的名字按照大写的方式显示
select upper(ename) from emp;
3. 显示正好为6个字符的员工的姓名
select *from emp where length(ename)=6;
4. 显示所有员工名字的前4个字符
select substr(ename,1,4)from emp ;
5. 以首字母大写的方式显示所有员工的姓名
select upper(substr(ename,1,1)) from emp;
6. 以首字母大写后面字母为小写的方式显示所有员工的姓名
a. 取出首字母为大写:select upper(substr(ename,1,1)) from emp;
b. 第二个字符到最后为小写:select lower(substr(ename,2,length(ename)-1)from emp;
c. Select upper(substr(ename,1,1))||lower(substr(ename,2,length(ename)-1)) from emp;
d. 合并这两个内容:
select upper(substr(ename,1,1))||lower(substr(ename,2,length(ename)-1))from emp;
replace (修改的字段,‘原字符’,‘修改后的字符’);
名字中的a替换成&
select replace(ename ,'A','&')from emp ;
instr(char_1,char_2,[n[,m]])取出字串在字符串中的位置
数学函数
数学函数的输入参数和返回值得数据类型都是数字类型。数学函数包括:cos,cosh,exp,ln,log,sin,sinh,sqrt,tan,tanh,acos,asin,atan,round,最常用的:
1. round(n,[m]); 用于执行四舍五入,如果去掉m就是四舍五入到整数,m为正数的时候,则四舍五入到小数点的m位后,如果为负数则四舍五入到小数点的m位前。
select ename ,(round(sal)+round(comm))*13 from emp;
select ename ,(round(sal,1)+round(comm))*13 from emp;
2. trunk(n,[m]);用于截取数字,如果省掉m,就截取小数部分,如过m是正数就截取到小数点的m位后,如果m是负数,则截取到小数点的前m位
select ename ,trunc(comm,2), comm from emp where ename='小鸡';
3. mod(m,n); 取模函数
select mod(10,2) from dual;\\dual表是用来测试的表(亚元表)再做oracle 测试的,虚拟的表
4. floor(n);返回小于或是等于n的最大整数(再这个整数向下取整)
select ename ,floor(comm) ,comm from emp where ename=’scott’;
5. ceil(n);返回大于或者等于n的最小整数(再这个整数向上取整)
select ename ,ceil(comm) ,comm from emp where ename=’scott’;
对数字的处理,长用再财务系统和银行系统中,不同的处理方法,对财务的报表有不同的结果。
显示在一个月为30天的情况下所有员工的日薪。忽略余数。
select trunc(sal/30),ename from emp;
select floor(sal/30),ename from emp;