oracle sql詳細總結版語句

2021-10-23 07:14:37 字數 4448 閱讀 4597

一、oracle的啟動和關閉

1、在單機環境下

要想啟動或關閉oracle系統必須首先切換到oracle使用者,如下

su - oracle

a、啟動oracle系統

oracle>svrmgrl

svrmgr>connect internal

svrmgr>startup

svrmgr>quit

b、關閉oracle系統

oracle>svrmgrl

svrmgr>connect internal

svrmgr>shutdown

svrmgr>quit

啟動oracle9i資料庫命令:

$ sqlplus /nolog

sql*plus: release 9.2.0.1.0 - production on fri oct 31 13:53:53 2003

copyright (c) 1982, 2002, oracle corporation. all rights reserved.

sql> connect / as sysdba

connected to an idle instance.

sql> startup^c

sql> startup

oracle instance started.

2、在雙機環境下

要想啟動或關閉oracle系統必須首先切換到root使用者,如下

su - root

a、啟動oracle系統

hareg -y oracle

b、關閉oracle系統

hareg -n oracle

oracle資料庫有哪幾種啟動方式

說明:有以下幾種啟動方式:

1、startup nomount

非安裝啟動,這種方式啟動下可執行:重建控制檔案、重建資料庫

讀取init.ora檔案,啟動instance,即啟動sga和後台程序,這種啟動只需要init.ora檔案。

2、startup mount dbname

安裝啟動,這種方式啟動下可執行:

資料庫日誌歸檔、

資料庫介質恢復、

使資料檔案聯機或離線,

重新定位資料檔案、重做日誌檔案。

執行「nomount」,然後開啟控制檔案,確認資料檔案和聯機日誌檔案的位置,

但此時不對資料檔案和日誌檔案進行校驗檢查。

3、startup open dbname

先執行「nomount」,然後執行「mount」,再開啟包括redo log檔案在內的所有資料庫檔案,

這種方式下可訪問資料庫中的資料。

4、startup,等於以下三個命令

startup nomount

alter database mount

alter database open

5、startup restrict

約束方式啟動

這種方式能夠啟動資料庫,但只允許具有一定特權的使用者訪問

非特權使用者訪問時,會出現以下提示:

error:

ora-01035: oracle 只允許具有 restricted session 許可權的使用者使用

6、startup force

強制啟動方式

當不能關閉資料庫時,可以用startup force來完成資料庫的關閉

先關閉資料庫,再執行正常啟動資料庫命令

7、startup pfile=引數檔名

帶初始化引數檔案的啟動方式

先讀取引數檔案,再按引數檔案中的設定啟動資料庫

例:startup pfile=e:oracleadminoradbpfileinit.ora

8、startup exclusive

二、使用者如何有效地利用資料字典

oracle的資料字典是資料庫的重要組成部分之一,它隨著資料庫的產生而產生, 隨著資料庫的變化而變化,

體現為sys使用者下的一些表和檢視。資料字典名稱是大寫的英文本元。

資料字典裡存有使用者資訊、使用者的許可權資訊、所有資料物件資訊、表的約束條件、統計分析資料庫的檢視等。

我們不能手工修改資料字典裡的資訊。

很多時候,一般的oracle使用者不知道如何有效地利用它。

dictionary   全部資料字典表的名稱和解釋,它有乙個同義詞dict

dict_column   全部資料字典表裡欄位名稱和解釋

如果我們想查詢跟索引有關的資料字典時,可以用下面這條sql語句:

sql>select * from dictionary where instr(comments,'index')>0;

如果我們想知道user_indexes表各欄位名稱的詳細含義,可以用下面這條sql語句:

sql>select column_name,comments from dict_columns where table_name='user_indexes';

依此類推,就可以輕鬆知道資料字典的詳細名稱和解釋,不用檢視oracle的其它文件資料了。

下面按類別列出一些oracle使用者常用資料字典的查詢使用方法。

1、使用者

檢視當前使用者的預設表空間

sql>select username,default_tablespace from user_users;

檢視當前使用者的角色

sql>select * from user_role_privs;

檢視當前使用者的系統許可權和表級許可權

sql>select * from user_sys_privs;

sql>select * from user_tab_privs;

2、表檢視使用者下所有的表

sql>select * from user_tables;

檢視名稱包含log字元的表

sql>select object_name,object_id from user_objects

where instr(object_name,'log')>0;

檢視某錶的建立時間

sql>select object_name,created from user_objects where object_name=upper('&table_name');

檢視某錶的大小

sql>select sum(bytes)/(1024*1024) as "size(m)" from user_segments

where segment_name=upper('&table_name');

檢視放在oracle的記憶體區里的表

sql>select table_name,cache from user_tables where instr(cache,'y')>0;

3、索引

檢視索引個數和類別

sql>select index_name,index_type,table_name from user_indexes order by table_name;

檢視索引被索引的字段

sql>select * from user_ind_columns where index_name=upper('&index_name');

檢視索引的大小

sql>select sum(bytes)/(1024*1024) as "size(m)" from user_segments

where segment_name=upper('&index_name');

4、序列號

檢視序列號,last_number是當前值

sql>select * from user_sequences;

5、檢視

檢視檢視的名稱

sql>select view_name from user_views;

檢視建立檢視的select語句

sql>set view_name,text_length from user_views;

sql>set long 2000說明:可以根據檢視的text_length值設定set long 的大小

sql>select text from user_views where view_name=upper('&view_name');

6、同義詞

檢視同義詞的名稱

sql>select * from user_synonyms;

7、約束條件

檢視某錶的約束條件

sql>select constraint_name, constraint_type,search_condition, r_constraint_name

from user_constraints where table_name = upper('&table_name');

sql>select

from user_constraints c,user_cons_columns cc

where c.owner = upper('&table_owner') and c.table_name = upper('&table_name')

ORACLE SQL效能優化38點總結

1.選用適合的oracle優化器 oracle的優化器共有3種 a.rule 基於規則 b.cost 基於成本 c.choose 選擇性 設定預設的優化器,可以通過對檔案中optimizer mode引數的各種宣告,如rule,cost,choose,all rows,first rows 你當然也...

礦井通風與安全總結詳細版

第一部分礦井瓦斯 1.煤與瓦斯突出 在採掘過程中,突然從煤 巖 壁內部向採掘空間噴出煤巖和瓦斯的現象,稱為煤與瓦斯突出,簡稱突出。2.瓦斯壓力 煤層裂隙和孔隙內由於氣體分子熱運動撞擊所產生的作用力。3.瓦斯含量 單位體積或重量的煤在自然狀態下所含有的瓦斯量 標準狀態下的瓦斯體積 包括游離瓦斯和吸附瓦...

房屋租賃合同詳細版

六 租賃期內,乙方承擔以下責任 1 依約按期繳納房屋租金。2 未經甲方書面同意,不得對房屋進行擴 加 改建或轉租 轉讓 分租,乙方保證不改變房屋用途。3 因使用需要進 屋內部裝修,須經甲方同意。4 因使用不當或人為造成房屋或原配置的裝置損壞的,乙方應負責賠償或修復。5 不得在承租的房屋內安裝或使用超...