ORACLE循序渐进讲解(第一讲)
由于工作原因很长一段时间没有使用oracle,最近花了点时间学习下,把自己所学的记录下来以便日后巩固(以10g为例)。
一、ORACLE 安装和卸载
二、登录ORACLE的方式
三、ORACLE用户管理
SQL> conn system/orcl Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as system SQL> create user test identified by test; User created SQL>
2、给用户修改密码
SQL> alter user system identified by scott1; User altered
3、删除用户
SQL> drop user test; User dropped注意如果想删除用户对应的数据对象时(如表)需要用加cascade 如drop user test cascade
SQL> create user test identified by test; User created SQL> grant connect to test; Grant succeeded SQL> conn test/test; Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as test SQL> show user User is "test"
5、授权用户对象权限(用system用户为test授权可select或update或delete或all操作scott用户的emp表)
SQL> conn system/orcl; Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as system SQL> grant select on scott.emp to test; Grant succeeded SQL> conn test/test; Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as test SQL> select * from scott.emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----- ---------- --------- ----- ----------- --------- --------- ------ 7369 SMITH CLERK 7902 1980-12-17 1800.00 20 7499 ALLEN SALESMAN 7698 1981-02-20 1600.00 300.00 30 7521 WARD SALESMAN 7698 1981-02-22 1250.00 500.00 30 7566 JONES MANAGER 7839 1981-04-02 2975.00 20 7654 MARTIN SALESMAN 7698 1981-09-28 1250.00 1400.00 30 7698 BLAKE MANAGER 7839 1981-05-01 2850.00 30 7782 CLARK MANAGER 7839 1981-06-09 2450.00 10 7788 SCOTT ANALYST 7566 1987-04-19 3000.00 20 7839 KING PRESIDENT 1981-11-17 5000.00 10 7844 TURNER SALESMAN 7698 1981-09-08 1500.00 0.00 30 7876 ADAMS CLERK 7788 1987-05-23 1100.00 20 7900 JAMES CLERK 7698 1981-12-03 950.00 30 7902 FORD ANALYST 7566 1981-12-03 3000.00 20 7934 MILLER CLERK 7782 1982-01-23 1300.00 34.56 10 14 rows selected
注:(1)grant select可换insert、update、delete、all。
SQL> conn scott/scott Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as scott SQL> create view v_test as 2 select ename,sal from emp; create view v_test as select ename,sal from emp ORA-01031: 权限不足 SQL> conn system/orcl; Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as system SQL> grant create view to scott; Grant succeeded SQL> conn scott/scott Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as scott SQL> create view v_test as 2 select ename,sal from emp; View created SQL> grant v_test to test; grant v_test to test ORA-01919: 角色 'V_TEST' 不存在 SQL> grant select on v_test to test; Grant succeeded SQL> select * from v_test; ENAME SAL ---------- --------- SMITH 1800.00 ALLEN 1600.00 WARD 1250.00 JONES 2975.00 MARTIN 1250.00 BLAKE 2850.00 CLARK 2450.00 SCOTT 3000.00 KING 5000.00 TURNER 1500.00 ADAMS 1100.00 JAMES 950.00 FORD 3000.00 MILLER 1300.00 14 rows selected
授权test用户只能修改sal字段。
SQL> grant update(sal) on emp to test; Grant succeeded
SQL> grant insert(empno,ename) on emp to test; Grant succeeded
6、收回用户对应权限。(用scott用户登录收回上面的v_test查询的权限和修改sal字段权限和插入empno,ename的权限)
SQL> CONN SCOTT/SCOTT Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as scott SQL> REVOKE SELECT ON V_TEST FROM TEST; Revoke succeeded SQL> REVOKE UPDATE(SAL) ON EMP FROM TEST; REVOKE UPDATE(SAL) ON EMP FROM TEST <span style="color:#ff0000;">ORA-01750: UPDATE/REFERENCES 只能从整个表而不能按列 REVOKE</span>
SQL> REVOKE UPDATE ON EMP FROM TEST; Revoke succeeded SQL> REVOKE INSERT ON EMP FROM TEST; Revoke succeeded注:注意上面的错误提示不能对表的某列revoke只能对整个表revoke。
SQL> CONN SCOTT/SCOTT Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as scott SQL> GRANT SELECT ON V_TEST TO TEST WITH GRANT OPTIONS; GRANT SELECT ON V_TEST TO TEST WITH GRANT OPTIONS <span style="color:#ff0000;">ORA-00994: 缺失 OPTION 关键字</span> SQL> GRANT SELECT ON V_TEST TO TEST WITH GRANT OPTION; Grant succeeded SQL> CONN TEST/TEST Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as test SQL> GRANT SELECT ON V_TEST TO TEST1; GRANT SELECT ON V_TEST TO TEST1 <span style="color:#ff0000;">ORA-00942: 表或视图不存在</span> SQL> GRANT SELECT ON SCOTT.V_TEST TO TEST1; Grant succeeded注:(1)权限的传递只需要在授权时加上with grant option就能让被授权的用户将些权限授予其他用户。
8、使用profile管理用户口令。
SQL> conn system/orcl Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as system SQL> create profile lock_account limit failed_login_attempts 2 password_lock_time 3; Profile created SQL> alter user test profile lock_account; User altered
<span style="color:#ff0000;">通过下面对用户强制解锁</span>
SQL> alter user test account unlock; User altered(设定用户定期修改密码,每隔10天修改自己的密码宽限期为3天)
SQL> create profile remind_account limit password_life_time 10 password_grace_time 3; Profile created SQL> alter user test profile remind_account; User altered删除直接drop profile remind_account;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。