100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > oracle数据库数值函数 五 oracle数据库常用函数

oracle数据库数值函数 五 oracle数据库常用函数

时间:2024-04-03 04:39:51

相关推荐

oracle数据库数值函数 五 oracle数据库常用函数

查看当前数据库的名字

select name from v$database

2.查看当前数据库实例名

select instance_name from v$instance

show parameters instance_name;

一个数据库可以有多个实例,在做数据库集群的时候可以用到

3.查看表空间的名字

select tablespace_name from dba_data_files

4.查看表空间里面有哪些表

select table_name from dba_tables where tablespace_name='USERS'

查看当前数据库的所有用户

select * from dba_users

6.查看表属于哪个表空间

select table_name,tablespace_name from all_tables where table_name='C'

7.查询用户有哪些操作权限

select * from user_sys_privs

8.oracle数据库的三范式

数据库的三范式

第一范式:不可能有重复的列,即存在的列不可再拆分

第二范式:非主属性完全依赖于主关键字

即存在组合关键字中的字段决定非关键字的情况。

不能存在两个主关键字来唯一标识该实体

第三范式:属性不依赖于其它非主属性

不存在关键字段 → 非关键字段x → 非关键字段y 如部门表中存在 部门编号,部门名称,部门位置

如果emp表中存在部门编号也就是说员工表中不能再有部门名称和部门位置了

9.union union all intersect 和minus的区别

union两个结果集的并集,会去除掉重复,默认会按查询结果的第一列升序排列。

union all 两个结果的并集不会去除重复,无序排列

intersect两个结果的交集,如表s1和s2这个就表示在s1和s2中公共的数据

minus两个结果集的差集,如表s1和s2这个表示在s1中的数据但是在s2中不存在

10.nvl和nvl2的区别

nvl(expr1,expr2)expr1为null时结果为expr2,值不为null时,结果为expr1

nvl2(expr1,expr2,expr3)expr1为null时结果为expr3,不为null时结果为expr2

11.oracle中常用的函数

length(字段名)查找字段的长度 concat(a,b)或者a||b 把a和b连接起来

round(n)四舍五入保留到整数位 round(n,1)保留一位小数 round(n,-1)保留整数位的第二位

instr(str,index)返回index在str中的位置,默认从1开始 initcap(str)首字母大写

lower(str)首字母小写 substr(str,start,count截取字符串,从某个位置开始,count表示从某个位置开始截取几位 extract(year from sysdate) 截取当前时间的年份 extract(month from sysdate)

replace(str,a,b)用b来替换str中的a rpad(字段名,长度,扩充值)有填充,如果该字段长度小于规定长度,就用扩充值在右边填充,rpad(str,7,'0') 如果str的长度小于7,就在str的后面补充0直到长度为7,lpad左填充同理。

ceil(15.6)向上取整,结果为16. ceil(-15.6)结果为-15

floor(15.6)向下取整,结果为15 floor(-15.6)结果为-16

mod(m,n)取余,mod(10,3)结果为1 power(n,p) 求n的p次幂 exp(n)一个数字的n次方根

trunc和round类似,只是trunc不会四舍五入 如trunc(15.6)结果为15,trunc(15.67,1)结果为15.6

to_char(日期,'yyyy-MM-dd') 日期转换为字符串 to_number(str)字符串转为数字,字符串必须是数字字符串

to_date(str,'yyyy-MM-dd')字符串转换为日期

sum()求和 ,count()计数 avg()求平均数 max()求最大值 min()求最小值

12.数据的导入和导出用来备份数据

exp scott/orcl file=G:\temps.dmp owner=scott consistent=y direct=y scott:用户名 orcl:密码 owner:用户名

imp nhsr/nhsr file=G:\temp.dmp ignore=y fromuser=scott touser=nhsr nhsr:要导入数据用户名 nhsr:要导入数据的密码

fromuser:数据来源用户 touser:要导入数据用户名

13.oracle中case when 和decode函数的使用

两者都是判断条件函数,decode(字段名,条件1,值1,条件2,值2....)当字段值为条件1时,值为值1,当字段值为条件2时,值为值2,每个判断条件对应一个值,最后如果没匹配成对的条件和值,结果相当于else。和if else if,else一样道理

select case when 条件1 then 值1

when 条件2 then 值2

.....else 值n

end 别名 from 表

14.数据库死锁查询以及kill进程语句

--(1)查看死锁对象

select s.username,l.object_id,l.session_id,s.SERIAL#,s.machine,s.STATUS from v

locked_objectl

where s.sid = l.session_id;

--(2)查看具体操作对象

select sql_text from v

session where sid in(select session_id from v$locked_object )

);

--(3)死锁处理语句(杀掉会话) 其中数字代表session_id,serial#

alter system kill session '393,63862

15.oralce创建用户一系列命令

create tablespace cat_data datafile 'J:/arms/cat_data.dbf' size 2048m autoextend on next 50m maxsize unlimited;创建表空间

win+r cmd 输入 sqlplus \ as sysdba 登录dba用户 ;conn可以切换用户

create user 用户名 identified by default tablespace密码 创建用户并指定默认的工作空间

grant connect,resource,dba,create session to 用户名 授予用户权限

alter user 用户名 identified by 密码 修改用户名和密码;

alter user 用户名 account unlock 解锁用户名

16、分组查询的两种写法:

select case

when degrees>60 and degrees<70 then '4'

when degrees>70 and degrees<80 then '3'

when degrees>80 and degrees<90 then '2'

when degrees>90 then '1'

else null end as 分数段,

count(*) from score

group by

case

when degrees>60 and degrees<70 then '4'

when degrees>70 and degrees<80 then '3'

when degrees>80 and degrees<90 then '2'

when degrees>90 then '1'

else null end

select sum(case when degrees>60 and degrees<70 then 1 else 0 end) as "60

sum(case when degrees>70 and degrees<80 then 1 else 0 end) as "70

sum(case when degrees>80 and degrees<90 then 1 else 0 end) as "80

sum(case when degrees>90 then 1 else 0 end) as "90

from score

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。