oracle基本笔记整理及案例分析1
2023-09-14 08:57:41 时间
/*
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数据库应用\tablespaces.dbf'
size 4M;
autoextend on; --或者on可不可以自动扩充
--扩展表空间,前提是已经存在了此空间
--1.更改数据库
alter database datafile 'E:\E盘\tablespaces.dbf' resize=8M;
--2.增加一个可扩展的数据库文件
alter database add datafile 'E:\E盘\tablespace2.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;
相关文章
- Oracle官方并发教程之同步
- 【Oracle】oracle的LAG和LEAD分析函数
- struts+hibernate+oracle+easyui实现lazyout组件的简单案例——struts.xml配置详情
- struts+hibernate+oracle+easyui实现lazyout组件的简单案例——DeptDao层代码
- struts+hibernate+oracle+easyui实现lazyout组件的简单案例——hibernate的config文件(hibernate.cfg.xml)
- struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Dept实体类和对应的配置信息
- oracle基本笔记整理及案例分析2
- 《oracle每日一练》免安装Oracle客户端使用PL/SQL
- oracle数据库高级应用之《自动生成指定表的insert,update,delete语句》
- Oracle systemstate dump介绍
- Oracle表连接的奇怪问题
- 【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之缓存融合技术和主要后台进程(四)
- 【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之RAC 工作原理和相关组件(三)
- Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之ORACLE集群概念和原理(二)
- Oracle 并行计算 JOIN HINT
- oracle sql语言模糊查询--通配符like的使用教程
- 安装oracle 11g rac (11.2.03) 出现PRVF-5637 错误
- Oracle创建简单视图案例
- Oracle 存储过程动态建表
- oracle 表连接 - hash join 哈希连接
- oracle存储过程的例子
- oracle解锁单个用户schema 批量解锁schema dbms_stats.unlock_schema_stats