Oracle学习笔记(二)

1.Oracle 的系统用户sys 是超级用户,具有sysdba权限,具有创建数据库的权限,默认密码为change_on_install。

而system为管理操作员,权限也很大,具有sysoper权限,但是没有create database的权限,默认密码为manager

2. 在Oracle中表、视图、存储过程、序列、函数等等通称为数据对象。

3. cmd中输入sqlplusw 进入SQL*PLUS

修改自己的密码: passw 新密码

显示当前用户:  show user;

运行sql脚本:  start d:\aaa.sql

编辑sql脚本文件:  edit d:\aaa.sql

将屏幕中的数据输入到文件中:

Spool bbb.sql;

Select * from test;

Spool off ;

交互式命令: select * from test where name=’&name’; 会弹出一个窗口提示 输入一个name

显示和设置环境变量:

Linesize 为每行显示的长度  show linesize  set linesize  50  默认为80

Pagesize 分页 set pagesize 12; 为打印一些报表服务的。

4.Dba权限的用户才能创建用户和修改用户密码,删除用户要具有drop user 的角色

Create  user heshan identified by a123;

给其他用户修改密码: password  heshan

删除用户:drop user heshan [cascade 级联删除表等数据库对象]

Grant 赋予权限 revoke  回收权限

新用户没有任何权限,没有登录到数据库的权限 (角色是权限的集合)

Grant connect to heshan;

Grant resource to heshan  在表空间里面建表的权限即可以使用表空间

Grant select on test to heshan(拥有表的用户可以授权)

Grant select on test to heshan with grant option(赋权给heshan 使heshan还可以赋给其他用户 但是只可以为对象权限)

如果为系统权限

Grant connect to heshan with admin option;

当回收权限的时候,传递的权限会被回收掉。

账户锁定:

Create profile lock_amount limit failed_login_attemps 3 password_lock_time  2;

(尝试三次 锁定2天)

Alert user heshan profile lock_amount;

Alert user heshan account unlock;

终止口令:

Create  profile myprofile limit password_life_time 10 password_grace_time  2;

(10天提醒修改密码,宽限期两天)

Alert user heshan profile myprofile; 

口令历史:

Create  profile paasword_history limit password_life_time 10 password_grace_time 2 paasword_reuse_time 10;

(10天提醒修改密码,宽限期两天,10天以后的可以重用) 

Drop profile myprofile;(删除口令文件)

5.表的管理

添加一个字段:

Alert table test add(name varchar(20));

Alert table test modified (name varchar(30));//修改表的字段长度

Alert table test drop column name; //删除表中一个字段

Rename test to test1;//修改表名

Set timing on;打开执行的时间

设置只读事物:set transaction read only;

Oracle在对数据处理的时候有隐性转换。

导出表:

Exp heshan/heshan123@orcl tables=(test) d:\aa.dmp //表数据 

Exp heshan/heshan123@orcl tables=(test) d:\aa.dmp rows=n //表结构

数据字典:

Select tables from user_tables;(all_tables   dba_tables)//查询用户所有的表

查询一个角色具有的权限

Select * from dba_sys_privs where grantee=’CONNECT’;

Select * from role_sys_privs where role=’CONNECT’;

查询某个用户具有的权限

Select * from dba_role_privs where grantee=’heshan’;

添加约束:

Alert table test add constraint  testUnique unqique(id);

调用函数:

命令行模式:

Var abc number;

Call test(‘heshan’) into:abc;

posted @ 2014-06-21 19:02  十年半山  阅读(243)  评论(0编辑  收藏  举报