1. 程式人生 > >oracle常用語法

oracle常用語法

oracle11g空表處理:
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;
然後將執行結果複製到另一個SQL視窗,並執行。


匯出: exp test/[email protected]_name file=c:\備份檔案.dmp owner=user
匯入: imp test/[email protected]_name file=c:\備份檔案.dmp fromuser=test touser=test
exp nempi/[email protected]

/ptai file=d:\empi.dmp owner=nempi
imp nempi/[email protected] 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/[email protected] file=d:\hlyy.dmp fromuser=hlyy touser=hlyy
imp nhbi_work/

[email protected] file=d:\nhbi_work.dmp fromuser=nhbi_work touser=nhbi_work

exp hlyy/[email protected] file=d:\hlyy.dmp owner=hlyy
exp nhbi_work/[email protected] file=d:\nhbi_work.dmp owner=nhbi_work

imp hlyy_ods/[email protected] 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/[email protected] file=d:\myqq.dmp fromuser=myqq touser=myqq

exp hlyy/[email protected] 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/[email protected] file=d:\kb.dmp owner=kb

imp kb/[email protected] 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;