`

oracle数据库操作

 
阅读更多

一、创建、删除空间
1.创建表空间:
Create tablespace tablespace_name
datafile 'D:\oracle_data\zhzc_gpc.dbf'
size 100M
autoextend on;
2.删除表空间
drop tablespace tablespace_name including contents;

二、创建、删除、授权对用户
1.创建用户
Create user user_name
identified by user_password
default tablespace tablespace_name
temporary tablespace temp_tablespace_name;
2.删除用户
drop user user_name cascade;
3.给用户授权
Grant connect,resource,dba to user_name;

三、导入、导出表
1.导入表
1).手工导出表
c:\Documents and Settings\Administrator>exp xygh/xygh@product
连接到:Oracle Database 10g Enterprise Edition Release 10.2.0.10-Production
With the Partitioning,OLAP and Data Mining options
输入数组提取缓冲区大小:4096>
导出文件:EXPDAT.DMP>d:\xygh_0831.dmp
(2)U(用户),或(3)T(表):(2)U>U
导出权限(yes/no):yes>
导出表数据(yes/no):yes>
压缩区(yes/no):yes>
2).Plsql导出
2.导入表
1).手工导入
c:\Documents and Settings\Administrator>imp pubservice/pubservice@PROJECT
连接到:Oracle Database 10g Enterprise Edition Release 10.2.0.10-Production
With the Partitioning,OLAP and Data Mining options
导入文件:EXPDAT.DMP>d:\xygh_0831.dmp
(2)U(用户),或(3)T(表):(2)U>U
导出权限(yes/no):yes>
导出表数据(yes/no):yes>
压缩区(yes/no):yes>
2).Plsql导入
注意事项:不同版本间数据库导入导出尊徐的规则不同。

四、数据库操作语句
1.无数据库管理员密码通道
sqlplus/nolog
conn/as sysdba
2.消除用户DBA权限
revoke dba from anhuitest;//清楚用户dba权限
3.系统用户登录查询所有用户
select username from all_users;
4.账户解锁
alter user process account unlock;
5.建立UNDO表空间,切换表空间
create undo tablespace undotbs02
datafile '/oracle/oradata/db/UNDOTBS02.dbf' size 50m
#注意:在OPEN状态下某些时刻只能用一个UNDO表空间,如果要用新建的表空间,必须切换到该表空间;
alter system set undo_tablespace=undotbs02;
6.使表空间只读
alter tablespace game read only;
7.使表空间可读写
alter tablespace game read write;
8.查看所有表空间
select tablespace_name from dba_free_space;
9.查看表空间的空余大小
select tablespace_name,sum(bytes)/1024/1024 mb
from dba_free_space group by tablespace_name;
10.扩展表空间
首先查看表空间的名字和所属文件
select tablespace_name,file_id,file_name,
round(bytes/(1024/1024),0) total_space
from dba_data_files
order by tablespace_name;


1.查看所有用户;
select * from dba_user;
select * from all_users;
select * from user_users;
2.查看用户系统权限;
select * from dba_sys_privs;
select * from all_sys_privs;
select * from user_sys_privs;
3.查看用户对象权限;
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;
4.查看所有角色;
select * from dba_roles;
5.查看用户所拥有的角色;
select * from dba_role_privs;
select * from user_role_privs;

修改列名
alter table xxx rename column aaa to bbb;
删除一列
alter table xxx drop column aaa;
增加一列
alter table add aaa varchar2(22);
修改某列的类型
alter table xxx modify aaa varchar2(22);
把某列的值赋给另一列
update xxx set aaa=bbb;
修改某一列允许为空(不为空)
alter table xxx modify aaa (not) null;
修改某一列的默认值
alter table xxx modify aaa default 1;
为某一列增加注释
comment on column xxx.aaa is 'abc...';
设置某一列为主键
alter table xxx add constraint PK_XXX primary key (aaa);
删除主键
alter table xxx drop constraint PK_XXX cascade;
增加(唯一)索引
create (unique) index IDX_XXX_AAA on xxx(aaa);

五、表数据操作
1.带编辑操作的plsql查询语句
select t.*,t.rowid from table_name t;
2.批量插入语句
insert into eps_pub_message (MSG_ID,RECEIVER)
select 'a'||u.usr_id,u.usr_id from auth_user u
where u.usr_id in('4324er34','4324325errgdfe54')
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics