oracle系统学习整理文档
一:oracle使用必须开两个服务,(一个是监听,一个是服务)。SYS和SYSTEM都是系统用户,只是SYS会有更大的权限。SYSTEM只能使用normal方式登录,而SYS只能以SYSDBA或SYSOPER角色登录。SYS的操作是不可逆的,谨慎使用。
1:安装oracle
2:创建表空间:create tablespace beyond datefile 'E:beyond.dbf' size 10M.
3:创建用户:create user bey identified by password default tablespace beyond.
4:赋权限:grant connect,resource to bey; grant select any table to bey;
5:在用户上建表。
二:oracle数据类型
1:number
(1):number(10) 表示整数位总共10位数字。
(2):number(10,2)表示总数为10位,整数位8位,小数位2位。
(3):number(10,-2)表示总共10位整数位,-2表示整数最后两位4舍5入取值,例如:
2:varchar2:变长字符串类型,最多4000字节,如果是空串则null处理,是oracle独有的。
3:char:固定长度存储,如果内容不满则用空格补上。
4:clob:存储大文本。
5:date:年月日时分秒都有。
三:关于数据库表
1:创建表 create table student (
name varchar(20),
age number,
sex char(1)
)
2:删除表 drop table student :当需要回滚删除的表 flashback table student to before drop;
3:删除表的内容:delete from student ;truncate table student; 注:truncate删除表时不需要提交事务,delete需要提交事务。
4:修改表 alter table student add course varchar(20)[增加列],
alter table student drop column course[删除列]
alter table student rename column course to course1[表重新命名列]
alter table student rename to stu[表重命名]
5:表中添加数据:insert into student (name,age,sex) values('张三','12','男')。
四:关于数据查询(函数)
(1):1:nvl(param1,param2):如果param1为空,则返回param2. nvl2(x,param1,param2)如果x非空返回param1,为空返回param2.
2:length:长度函数。
3:initcap:将字段第一个字母大写,其他为小写。
4:instr(abcdea,c,指定位置):查找c在abcdea中出现的第一个位置。
5:concat(x,y):连接字符串x,y。
6:lower:将字符串改为小写。
7:upper:将字符串改为大写。
8:ASCII(x):返回字符串x的ASCII码。
9:trim(x):去空格,还有ltrim,rtrim。
10:replace(x,old,new):在x中查找old并替换成new。
11:substr(x,start,length):从start开始截取length位。
(2):聚合函数:avg,sum,min,max,count
(3):数字函数:
1:abs(-3)=3.
2:ceil(5.4)=6.
3:floor(5.8)=5
4:log(x,y):x为底y的对数。
5:mod(x,y):x除以y的余数。
6:power(x,y):x的y次幂。
7:round(x,y):x四舍五入保留y位。
8:trunc(x,y):x在第y位截断。
9:sqrt(x):x的平方根。
浙公网安备 33010602011771号