Oracle小记

浏览: 2047

一.赋权限

  1.基本的赋权

  grant connect to user;

  grant resource to user;

  grant dba to user;

  2.权限的继续转发

  grant select on t_emp to user with option

  3.对于某表可以进行增删改查

  grant all on t_emp to user;

  grant select/update/delete/insert/create index on t_emp to user;

  4.回收权限

  revoke all on t_emp from user;权限回收级联


二.使用profile管理用户口令
  1.创建
  conn system/manager;
  create profile account limit failed_login_attempts 3 password_lock_time 2;
  accout 指帐户,3 3次密码输入 2 帐户锁定2天
  alter user scott profile account;
  密码错误锁2天;
  解锁:alert user scott account unlock;
  *******************************************
  要求用户每隔10天修改密码,期限2天
  create profile myprofile limit password_life_time 10 password_grace_time 2;
  alter user scott profile myprofile;
  *********************************************
  create profile myprofile limit password_life_time 10 password_grace_time 2
  password_reuse_time 10;
  password_reuse_time//指定口令10天后可以使用
  **********************************************
  drop profile myprofile 删除profile

三.创建用户用户名 
   create user 用户名 identified by 密码
   password 用户名
   alter user 用户名 identified by 新密码
   drop user [cascade] cascade级联删除 把该用户下的表级联删除

四.表管理
   设置保存点 savepoint aa;
   恢复到某个保存点 rollback to aa;只有一个保存点
   删数据 truncate table student;删除速度快 但是不可恢复数据 不写入日志

五.表查询

   select max(sal),avg(sal),deptno from emp group by deptno;
   按那个字段分组,那个字段必须出现在select中

   select avg(sal),max(sal),deptno,job from emp group deptno,job;

   select deptno,avg(sal) from emp group by deptno having avg(sal)>2000;

   对数据分组的总结
   1.分组函数只能出现在选择列表、having、order by 字句中
   2.顺序:group by --having---order by


   多表查询
   select e.name,e.sal,d.dname from emp e,dept d where e.deptno=d.deptno;
   
   笛卡尔集 select e.name,e.sal,d.dname from emp(14) e,dept(5) d 
   ----不加条件就是笛卡尔集14*5
   多表查询的条件是 至少不能少于表的个数-1

   内嵌视图就是把子查询作为一个视图来对待
*********************************
   oracle分页一共有三种方式
   1.rownum分页

   select * from (select a1.* , rownum rn from (select * from emp) a1 where rownum<=10) where rn>=6;

   几个变化
     a.指定查询列,只需修改最底层的查询
   2.根据ROWID来分

   select * from t_xiaoxi where rowid in (select rid from(select rownum rn,rid(select 
   rowid rid,cid from t_xiaoxi order by cid desc) where row num<10000 ) where rn>9980) order by cid desc;

    (1)(select rowid rid,cid from t_xiaoxi order by cid desc) A
    (2)(select rownum rn,rid from A where rownum<10000) B
    (3)(select rid from B where rn>9980) C
    (4)(select * from t_xiaoxi where rowid in (C) order by cid desc)

**************
    合并查询 union 不去重,不排序 
    一般用 union all 
    minus 差集 集合-集合
    
****************
使用工具创建数据库 
Database Configuration Assitant;

***************
2011.08.30

1.Oracle与Java交互,Oracle分页 见韩顺平12讲

2.Oracle事务处理 java交互 13讲

**************
2011.09.02
1.replace 用我替代A
select replace(ename,'A',‘我’) from emp;
2.round 四舍五入
round(sal,1) 保留一位小数
3.trunc 截取
4.floor(n) 返回小于或等于n的最大整数
5.ceil(n) 返回大于或等于n的最小整数
6.mod 取模 mod(10,3) = 1
7.add_months
  select * from emp where sysdate>add_months(hiredate,8);
8.一个用户一个方案
  用户pmsi     方案中有表,视图,包,过程等

数据库管理:
 ## 安装和升级oracle数据库
 ## 建库,表空间,表,视图,索引。。。
 ## 制定并实施备份与恢复计划
 ## 数据库权限管理,调优,故障排除
 ## 对于高级dba,要求能参与项目开发,会编写sql语句,存储过程,触发器,规则,约束,包

2011.09.04

SYSDBA可以关闭数据库,shutdown,startup

数据字典:user_xxx,all_xxx,dba_xxx三种
eg:
   user_tables:当前用户下的表
   all_tables:当前用户可以查看的表
   dba_tables:所有方案拥有的数据库表,要求该用户拥有dba角色或有select any table 
   权限

数据字典基表或视图:
   dba_user:可以显示所有数据库用户的详细信息
   dba_sys_privs,可以显示用户所具有的系统权限;
   dba_tab_privs,可以显示用户具有的对象权限;
   dba_col_privs,可以显示用户具有的列权限;
   dba_role_privs,可以显示用户所具有的角色。

查询oracle中所有的系统权限,一般是dba
select * from system_privilege_map order by name;
查询oracle中的所有的角色,一般是dba
select * from dba_roles;
查询oracle中的所有对象权限,一般是dba
select distinct privilege from dba_tab_privs;
查询数据库的表空间
select tablespace_name from dba_tablespaces;

推荐 1
本文由 olfisher 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册