oracle基本笔记整理及案例分析1

/*
Oracle数据库的应用
*/

--创建一个自动增长的表空间worktbs
create tablespace worktbs
datafile 'E:E盘worktbs01.dbf'
size 10M autoextend on;

--删除表空间
--drop tablespace worktbs;

--在表空间里面创建一个新用户
create user martin            --用户名
identified by martin          --密码
default tablespace worktbs    --默认表空间
temporary tablespace temp     --临时表空间
grant all privileges to martin;
--修改martin用户的密码为mpwd
--alter user martin identified by mpwd;

--删除用户martin
--drop user martin cascade;

--给用户授权权限
grant connect,resource to martin;
--给用户撤销角色
revoke connect,resource from martin;
--允许用户查看emp中的表
grant select on scott.emp to martin;
--允许用户更新emp中的表
grant update on scott.emp to martin;

/*
序列
*/
--创建序列
create sequence seql                --序列名字
start with 1                        --从1开始
increment by 1                      --每次加1
maxvalue 2000                       --最大为2000
nocycle                             --不循环,循环的话是cycle
cache 30                            --缓冲30个序列号
select sys_guid() from dual;
/*
访问序列
nextval    每次返回下一个值   序列名.nextval (seql.nextcval)
currval    每次返回当前的值   序列名.currval  (swql.currval)
*/

--更改序列(注:不能修改序列中的参数 strat with)
/*alter sequence seql 
increment by 2                      --每次增长2
maxvalue 30000                      --最大值是30000
minvalue 20                         --最小值是20
cycle                               --重复
*/

--删除序列
--drop sequence seql

--使用sys_guid来生成32位唯一编码的数字
select sys_guid() from dual;


/*
同义词
*/
--私有同义词
--获得访问scott模式下的emp表(创建同义词)
create synonym sy_emp for scott.dept;
--访问同义词
select * from sy_emp;
--公有同义词
--在test模式下对员工表employee创建公有的同义词(public_sy_emp)
--目的是使用某个用户直接访问该表
create public synonym public_sy_emp for test.employee;
--访问该公有同义词
select * from public_sy_emp;

--删除同义词
--drop [public] synonym 同义词名字 

/*
索引
*/
--创建索引
--create [unique(是否为唯一索引)] index_name on table_name (列名) [表空间]

--在employee里面为员工编号empno列创建反向索引
--create index index_reverse_empno on employee(empno) reverse;

--位图索引
--在employee里面,为job列创建位图索引
--create bitmap index index_bit_job   --索引名
--on employee(job);

--其他索引
--在employee表中,为员工名称ename列创建大写函数索引
--create index index_ename on employee (upper(ename));



/*
===========================================================================================
                                分割线
===========================================================================================
*/
--创建表空间
create tablespace tablespaces datafile 'E:E盘第三期Y2内容1.oracle内容第一本书使用Hibernate开发租房系统第二章oracle数据库应用	ablespaces.dbf'
size 4M;
autoextend on;    --或者on可不可以自动扩充

--扩展表空间,前提是已经存在了此空间
--1.更改数据库
alter database datafile 'E:E盘	ablespaces.dbf' resize=8M;

--2.增加一个可扩展的数据库文件
alter database add datafile 'E:E盘	ablespace2.dbf'
autoextend on;

--删除表空间(包括和他相关的全部删掉)
--drop tablespace tablespaces include contents ;

--创建用户
create user username
identified by 123
default tablespace tablespaces --指定表空间

--删除表空间
drop user username;


--权限
grant connect,resouce to martin;
grant create public synonym to username;   --给用户一个创建公有同义词的权限

/*

1.system授权grant create public synonym to username;
2.在username里面创建同义词
3.在username给目标用户授权(select)

*/
--创建同义词
create or replace public synonym public_toys for scott.emp;

原文地址:https://www.cnblogs.com/a1111/p/6540247.html