oracle常用语法

oracle11g空表处理:
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;
然后将执行结果复制到另一个SQL窗口,并执行。


导出: exp test/test@server_name file=c:\备份文件.dmp owner=user
导入: imp test/test@server_name file=c:\备份文件.dmp fromuser=test touser=test
exp nempi/[email protected]/ptai file=d:\empi.dmp owner=nempi
imp nempi/empi@orcl file=D:\Neusoft\Project\N南京儿童医院\empi.dmp fromuser=nempi touser=nempi
CREATE SEQUENCE emp_sequence --序列名
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;


imp hlyy/hlyy@orcl file=d:\hlyy.dmp fromuser=hlyy touser=hlyy
imp nhbi_work/nhbi@orcl file=d:\nhbi_work.dmp fromuser=nhbi_work touser=nhbi_work

exp hlyy/hlyy@orcl file=d:\hlyy.dmp owner=hlyy
exp nhbi_work/nhbi@orcl file=d:\nhbi_work.dmp owner=nhbi_work

imp hlyy_ods/hlyy@orcl file=d:\hlyy_ods.dmp fromuser=hlyy_ods touser=hlyy_ods ignore=y DESTROY=y
exp myqq/[email protected]/orcl file=d:\myqq.dmp owner=myqq

imp myqq/myqq@orcl file=d:\myqq.dmp fromuser=myqq touser=myqq

exp hlyy/hlyy@orcl file=e:\hlyy.dmp owner=(hlyy,hlyy_ods,hlyy_itf,nhbi_work)

/*分为四步 */
/*第1步:创建临时表空间 */
create temporary tablespace yuhang_temp
tempfile 'D:\oracledata\yuhang_temp.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;

/*第2步:创建数据表空间 */
create tablespace yuhang_data
logging
datafile 'D:\oracledata\yuhang_data.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;

/*第3步:创建用户并指定表空间 */
create user yuhang identified by yuhang
default tablespace yuhang_data
temporary tablespace yuhang_temp;

/*第4步:给用户授予权限 */
grant connect,resource,dba to yuhang;


exp kb/plhlyy@orcl file=d:\kb.dmp owner=kb

imp kb/plhlyy@orcl file=C:\Users\wangw\Desktop\kb\kb.dmp fromuser=kb touser=kb


--表空间
SELECT a.tablespace_name "表空间名",
round(total/(1024 * 1024 * 1024),4) "表空间大小",
round(free/(1024 * 1024 * 1024),4) "表空间剩余大小",
round((total - free)/(1024 * 1024 * 1024),4) "表空间使用大小",
round(total / (1024 * 1024 * 1024),4) "表空间大小(G)",
round(free / (1024 * 1024 * 1024),4) "表空间剩余大小(G)",
round((total - free) / (1024 * 1024 * 1024),4) "表空间使用大小(G)",
round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free
FROM dba_free_space
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total
FROM dba_data_files
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
order by round((total - free) / total, 4) * 100 desc

--表空间是否自增长
select file_id,file_name,tablespace_name,autoextensible,increment_by from dba_data_files order by file_id desc;

--CDR加表空间
alter tablespace CDRDATA add datafile 'D:\APP\ADMINISTRATOR\ORADATA\ORCL\CDR\CDRDATA7.DBFF' size 30G autoextend on next 30M;

猜你喜欢

转载自www.cnblogs.com/wwzd/p/9951676.html