Oracle SqlpLus 命令,惡補啊!(一)

2021-08-29 22:27:47 字數 4949 閱讀 4639

一、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

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 54ne.com

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 許可權的使用者使用 中國網管聯盟www、bitscn、com

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';

中國網管聯盟www_bitscn_com

依此類推,就可以輕鬆知道資料字典的詳細名稱和解釋,不用檢視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

中國網管聯盟www.bitscn.com

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; 中國網管論壇bbs.bitscn.com

檢視索引被索引的字段

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;

54ne.com

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 c.constraint_name,c.constraint_type,cc.column_name

from user_constraints c,user_cons_columns cc

網管網bitscn.com

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

and c.owner = cc.owner and c.constraint_name = cc.constraint_name

order by cc.position;

8、儲存函式和過程

檢視函式和過程的狀態

sql>select object_name,status from user_objects where object_type='function';

sql>select object_name,status from user_objects where object_type='procedure';

檢視函式和過程的源**

sql>select text from all_source where owner=user and name=upper('&plsql_name');

Oracle sqlplus 登入命令

1 執行sqlplus工具 c users wd pc sqlplus 2 直接進入sqlplus命令提示符 c users wd pc sqlplus nolog 3 以os身份連線 c users wd pc sqlplus as sysdba 或 sql connect as sysdba 4...

Oracle sqlplus語句編輯命令

首先我們輸入這樣一條指令 select emp id,emp name from employees input where emp age 30 便可得到如下指令 select emp id,emp name from employees where emp age 30 ln 命令用於指定對以輸...

Oracle sqlplus語句編輯命令

首先我們輸入這樣一條指令 select emp id,emp name from employees input where emp age 30 便可得到如下指令 select emp id,emp name from employees where emp age 30 ln 命令用於指定對以輸...