sys,system;sysman;scott
使用者登入格式:[username/password] [@server] [as sysdba|sysoper]
system/orcl @orcl as sysdba
備註:orcl 就是自己設定的服務名system/orcl
如果已經使用某個使用者登入了sql plus,切換登入使用者:
connect sys/orcl as sysdba
備註:書寫不區分大小寫
show user
備註:sqlplus 中輸入的命令不需要分號,當輸入的是sql語句時需要加分號
通過」資料字典」—dba_users(資料庫提供的表,也是由很多的字段組成)檢視使用者的其他字段資訊
檢視資料字典中的字段:
desc dba_users
通過資料字典檢視有多少個使用者:
select username from dba_users;
使用scott使用者登入sqlplus:(scott使用者的預設密碼是tiger)
connect scott/tiger
表空間:
資料庫的邏輯儲存空間,可以理解為在資料庫中開闢的空間用來儲存資料庫物件;
表空間和資料檔案的關係:
表空間由乙個或多個資料檔案組成;資料檔案的大小和位置可以自己定義;
表空間的分類:
永久表空間:資料庫中要永久化儲存的一些物件,如:表、檢視、儲存過程
臨時表空間:資料庫操作當中中間執行的過程,執行結束後,存放的內容會被自動釋放
undo表空間:用於儲存事務所修改資料的舊值,可以進行資料的回滾
①資料字典
dba_tablespaces(系統管理員級別檢視的資料字典)
user_tablespaces(普通使用者檢視的資料字典)
②.檢視表空間的字段
desc dba_tablespaces
③.檢視有幾個表空間
select tablespace_name from dba_tablespaces;
⑤.檢視使用者的字段資訊
desc dba_users
⑥.檢視使用者的預設表空間、臨時表空間等等
select default_tablespace from dba_users where username=』sys』;
alter user username default|tempporart tablespace tablespace_name;
備註:普通使用者沒有設定表空間的許可權
①.建立表空間
create [temporary] tablespace tablespace_name tempfile|datafile 『xx.dbf』 size xx;
備註:如果建立的是臨時表空間,需要加上temporary關鍵字;
②.檢視表空間的具體路徑:(通過dba_data_files 和 dba_temp_files這個資料字典)
desc dba_data_files
select file_name from dba_data_files where tablespace_name=」;(條件是表空間的名字,需要大寫)
③.修改表空間的狀態
設定聯機或離線的狀態(表空間是離線時不可用,預設是聯機的)
alter tablespace tablespace_name online|offline;
如何知道表空間所處的狀態?(通過這個dba_tablespaces資料字典)
desc dba_tablespaces
select status from dba_tablespaces where tablespace_name=」;(條件是表空間的名字,需要大寫)
設定唯讀或可讀寫的狀態(只有在聯機狀態才可以更改,預設的聯機狀態就是讀寫狀態)
alter tablespace tablespace_name read only | read write;
④.修改資料檔案
增加資料檔案
alter tablespace tablespace_name add datafile 『xx.dbf』 size xx;
select file_name from dba_data_files where tablespace_name=」;(條件是表空間的名字,需要大寫)
備註:通過這條select語句就查詢到當前表空間中的資料檔案
刪除資料檔案(不能刪除表空間當中第乙個資料檔案,如果要刪除就需要刪除整個表空間)
alter tablespace tablespace_name drop datafile 『xx.dbf』;
⑤.刪除表空間
drop tablespace tablespace_name[including contents];
10 Oracle使用者管理
使用者管理 建立乙個使用者從無到有,再分配許可權,在到墮落以及刪除的過程,如果要想進行使用者的建立,那麼必須有管理員的許可權,本次就直接使用sys使用者。使用sys登入 1 sys登陸 conn sys change on install as sysdba 2 建立乙個新的使用者,名字為 dog,...
Oracle常用命令10 oracle例外處理
例外傳遞 如果不處理例外我們看看會出現什麼情況 案例,編寫乙個過程,可接收雇員的編號,並顯示該雇員的姓名。問題是,如果輸入的雇員編號不存在,怎樣去處理呢?例外案例 declare 定義 v ename emp.ename type begin 執行 select ename into v ename...
Oracle常用命令10 oracle例外處理
例外傳遞 如果不處理例外我們看看會出現什麼情況 案例,編寫乙個過程,可接收雇員的編號,並顯示該雇員的姓名。問題是,如果輸入的雇員編號不存在,怎樣去處理呢?例外案例 declare 定義 v ename emp.ename type begin 執行 select ename into v ename...