acc
(zcaid number,zraid number,accountes INOUTnumber)
is flags number;
begin update accounts set money=money+accountes where aid=zraid returning flag into flags;
ifsql%rowcount=0then raise_application_error(-20002,'目標(biāo)賬號(hào)不存在');
elsif(flags=1)then raise_application_error(-20003,'目標(biāo)賬號(hào)已被鎖定');
endif;
update accounts set money=money-accountes where aid=zcaid returning money into accountes;
if(accountes=10)then raise_application_error(-20004,'你帳戶(hù)余額不足十元請(qǐng)取消操作');
endif;
commit;
end;
---
DECLARE v1NUMBER:=300;
BEGIN acc(9,10,v1);
dbms_output.put_line(v1);
END;
包的使用
CREATEORREPLACEPROCEDURE hello(
p_emp INOUT emp.ename%TYPE
)
---
AS BEGIN p_emp:=upper(p_emp);
dbms_output.put_line('hello,'||p_emp);
END;
CREATEORREPLACEPACKAGE bao_1 AS PROCEDURE hello(p_emp emp.ename%TYPE);
FUNCTION add_number(a NUMBER,b NUMBER)RETURNNUMBER;
END;
CREATEORREPLACEPACKAGEBODY bao_1 AS PROCEDURE hello(p_emp emp.ename%TYPE)
AS BEGIN
--p_emp:=upper(p_emp);
dbms_output.put_line('hello,'||p_emp);
END;
FUNCTION add_number(a NUMBER,b NUMBER)RETURNNUMBER AS BEGIN RETURN NVL(a,0)+NVL(b,0);
END;
END;
CALL bao_1.hello('lovo');
SELECT bao_1.add_number(10,NULL)FROM dual;
createorreplaceprocedure acc
(zcaid number,zraid number,accountes INOUTnumber)
is flags number;
begin update accounts set money=money+accountes where aid=zraid returning flag into flags;
ifsql%rowcount=0then raise_application_error(-20002,'目標(biāo)賬號(hào)不存在');
elsif(flags=1)then raise_application_error(-20003,'目的賬號(hào)已被鎖定');
endif;
update accounts set money=money-accountes where aid=zcaid returning money into accountes;
if(accountes=10)then raise_application_error(-20004,'你帳戶(hù)余額不足十元請(qǐng)撤消操作');
endif;
commit;
end;
---
DECLARE v1NUMBER:=300;
BEGIN acc(9,10,v1);
dbms_output.put_line(v1);
END;
select*from accounts
--特點(diǎn):無(wú)返回值存儲(chǔ)過(guò)程
Connection conn=.;
String spName="{call acc(?,?,?)}";
CallableStatement cstmt=conn.prepareCall(spName);
cstmt.setString(1,"值");
…
cstmt.executeUpdate();
--特色:有返回值存儲(chǔ)過(guò)程,返回一個(gè)值
Connection conn=.;
String spName="{call acc(?,?,?)}";
CallableStatement cstmt=conn.prepareCall(spName);
cstmt.setInt(1,9);
cstmt.setInt(2,10);
cstmt.setInt(2,150);
cstmt.registerOutParameter(3,java.sql.Types.DOUBLE);
cstmt.executeUpdate();
int money=cstmt.getInt(3);
System.out.println("余額:"+money);
1.只讀事務(wù)--只讀事務(wù)
只讀事務(wù)是指只容許執(zhí)行查詢(xún)的事務(wù),而不許可執(zhí)行其它任何dml
操作的事務(wù),使用只讀事務(wù)可以確保用戶(hù)只能獲得某時(shí)光點(diǎn)的數(shù)據(jù),
假定:機(jī)票代售票點(diǎn)天天18點(diǎn)開(kāi)端統(tǒng)計(jì)今天的銷(xiāo)售情況,這時(shí)可以
應(yīng)用只讀事務(wù),在設(shè)置了只讀事務(wù)后,只管其它會(huì)話(huà)可能會(huì)提交新的事務(wù)
,然而只讀事務(wù)將不會(huì)取得新數(shù)據(jù)的變更,從而可以保障取得特定時(shí)間
點(diǎn)的數(shù)據(jù)信息。
--在做統(tǒng)計(jì)的時(shí)候同時(shí)也在賣(mài)票。不可能在統(tǒng)計(jì)的統(tǒng)計(jì)的時(shí)候不答應(yīng)賣(mài)票
--設(shè)置吟詩(shī)事務(wù)
settransactionreadonly
--示例:1.以system登陸
再set transactionreadonly
連到scott/tiger登陸,select*from emp;有18行列出來(lái)了
再增加一條數(shù)據(jù)
insertinto emp(empno,ename,hiredate)values(111,'zbm',to_date('2000-10-01','yyyy-mm-dd'));
commit;
在scott中能看得到該用戶(hù)zbm
在system用戶(hù)中不能看到該用戶(hù)zbm--select*from scott.emp;
--在個(gè)用戶(hù)中設(shè)置了只讀事務(wù),之后的操作就不能讀出來(lái)了。
--一般主要用在機(jī)票代售點(diǎn),銀行的本錢(qián)的統(tǒng)計(jì),職員工資的統(tǒng)計(jì)
--字符函數(shù)
lower(char):將字符串轉(zhuǎn)成小寫(xiě)的格式
upper(char):將字符串轉(zhuǎn)居大寫(xiě)的格式
length(char):返回字符串的長(zhǎng)度
substr(char,m,n):取字符串的子串
replace(char,search_string,repalce_string)
--將姓名按小/大寫(xiě)顯示
select lower(ename)from emp;
select upper(ename)from emp;
--顯示正好為5個(gè)字符的員工姓名
select ename ename from emp where length(ename)=5;
--顯示所有員工的前三個(gè)字符
select substr(ename,0,3)from emp;
--以首字母大寫(xiě)的方式顯示所有的員工
select upper(substr(ename,0,1))||lower(substr(ename,1,len gth(ename)-1))from emp;
--以首字母小寫(xiě)的方式顯示所有的員工
select lower(substr(ename,0,1))||upper(substr(ename,1,len gth(ename)-1))from emp;
--把名字中的a字母替為我
selectreplace(ename,'A','我')from emp;
--數(shù)字函數(shù)
round(n,[m]):四舍五入,沒(méi)m舍到整數(shù),m為正數(shù),舍到小數(shù)后m位,m為負(fù)數(shù),舍到數(shù)前m位
trunc(n,[m]):截取數(shù)字,與round一樣,只不外前者是四舍五入,后者是截取
mod(m,n):取模
floor(n):返回小于或等于n的最大整數(shù)
ceil(n):返回大于n或即是n的最小整數(shù)
--對(duì)數(shù)字的處理,在財(cái)務(wù)系統(tǒng)或在銀行頂用的最多,不同的處理辦法
--對(duì)賬務(wù)報(bào)表有不同的成果
用四種方法算年薪
用round select(round(sal)+round(comm))*13as年薪from emp where ename='ALLEN';--24700 select(round(sal,2)+round(comm,2))*13as年薪from emp where ename='ALLEN';--24877
用trunc select(trunc(sal)+trunc(comm))*13as年薪from emp where ename='ALLEN';--24700
用floor,用ceil一樣
selectmod(10,3)from dual;--1
--例,數(shù)據(jù):2345.56 45.94
--顯示在一個(gè)月為30天的情況下所有員工的日薪金,疏忽余數(shù)
select*from emp forupdate;
--用
oracle第四天
--日期專(zhuān)題
日期函數(shù)用于處置date類(lèi)型的數(shù)據(jù),默認(rèn)日期格局是:dd-mon-yy即12-7月-78 1).sysdate:該函數(shù)返回系統(tǒng)時(shí)間selectsysdatefrom dual;
2).add_months(d,n)
3).last_day(d):返回指定日期所在月份的最后一天
--題目一:查找已經(jīng)入職8個(gè)月多的員工
select*from emp wheresysdate add_months(hiredate,200);
--題目二:顯示滿(mǎn)10年服務(wù)年限的員工的姓名和受雇日期。
select ename,hiredate from emp wheresysdate add_months(hiredate,120);
--題目三:對(duì)于每一個(gè)員工,顯示其參加公司的天數(shù)。
select ename,sysdate-hiredate as"入職天數(shù)"from emp;
--標(biāo)題四:找出各月倒數(shù)第3天受雇的所有員工。(在結(jié)賬的時(shí)候很有用)
select hiredate,last_day(hiredate),last_day(hiredate)-2from emp;
--轉(zhuǎn)換函數(shù)
1.不必函數(shù)也能轉(zhuǎn)換
insertinto emp(empno,ename)values('001','張三豐');
2.字符串轉(zhuǎn)化函數(shù)
select ename,to_char(hiredate,'yyyy-mm-dd hh24:mi:ss')from emp;
select ename,to_char(sal,'L 99999.999')from emp;--L表示本地的貨幣符號(hào)
select ename,to_char(sal,'L99,999.99')as rmb from emp;--L表現(xiàn)本地的貨泉符號(hào)
select ename,to_char(sal,'$99,999.99')as rmb from emp;
3.顯示1980年入職的員工
select*from emp where to_char(hiredate,'yyyy')=1981;
4.顯示所有12月份入職的員工
select*from emp where to_char(hiredate,'mm')=12;
1.數(shù)據(jù)庫(kù)管理員,管理員有基礎(chǔ)職責(zé)
2.數(shù)據(jù)庫(kù)/表的邏輯備份與恢復(fù)
3.數(shù)據(jù)字典和動(dòng)態(tài)機(jī)能視圖
4.管理表空間和數(shù)據(jù)文件,數(shù)據(jù)字典,性能視圖
解釋?zhuān)好總€(gè)數(shù)據(jù)庫(kù)應(yīng)當(dāng)至少有一名數(shù)據(jù)庫(kù)管理員dba
,但我國(guó)中小企業(yè)個(gè)別不,至公司的dba做什么呢?
--職責(zé)
1).安裝和進(jìn)級(jí)oracle數(shù)據(jù)庫(kù)
2).建庫(kù),表空間,表,視圖,索引.
3).制訂并實(shí)行備份與恢復(fù)打算
4).數(shù)據(jù)庫(kù)權(quán)限治理,調(diào)優(yōu),故障消除--重點(diǎn)
5).對(duì)高等dba,請(qǐng)求能參加名目開(kāi)發(fā),會(huì)編寫(xiě)sql語(yǔ)句服務(wù)器數(shù)據(jù)恢復(fù),存儲(chǔ)進(jìn)程
,觸發(fā)器,規(guī)矩,約束,包
--體系函數(shù)
1.查看當(dāng)前用戶(hù),及當(dāng)前數(shù)據(jù)庫(kù)--db_name
在sqlplus下show user;
或
select sys_context('userenv','session_user')from dual;
select sys_context('userenv','db_name')from dual;--orcl 2.查看當(dāng)前所用語(yǔ)言---language select sys_context('userenv','language')from dual;
3.顯示當(dāng)前會(huì)話(huà)客戶(hù)所對(duì)應(yīng)的默認(rèn)方案名--方案和用戶(hù)關(guān)系?
--用戶(hù)創(chuàng)立之后,會(huì)主動(dòng)創(chuàng)建一個(gè)方案,方案與用戶(hù)同名,方案中有各種
--對(duì)象,如觸發(fā)器,表,視圖,過(guò)程等
select sys_context('userenv','current_schema')from dual;
4.顯示當(dāng)前主機(jī)名
select sys_context('userenv'數(shù)據(jù)恢復(fù),'host')from dual;
sys和system比擬1.存儲(chǔ)數(shù)據(jù)的主要性不同
占有數(shù)據(jù)庫(kù)管理員角色dba
--sys用戶(hù):(其方案中有基表,動(dòng)態(tài)視圖)系統(tǒng)管理員角色sysdba
系統(tǒng)操作員角色sysoper
角色:數(shù)據(jù)庫(kù)管理員角色dba
--system用戶(hù):(方案中為次級(jí)數(shù)據(jù):)系統(tǒng)管理員角色sysdba 2.權(quán)限不同
1).sys用戶(hù)必須以as sysdba或as sysopr情勢(shì)登陸,不能以nomal方式登陸數(shù)據(jù)庫(kù)
system是畸形登陸,它其實(shí)就是一個(gè)一般的dba用戶(hù),但作為as sysdba登陸,其結(jié)果
實(shí)際上它作為sys用戶(hù)登錄的,從登陸信息咱們可以看出。
sqlplus sys/tigertiger assysdba可以登陸
conn sys/tigertiger;--你不再銜接到ORACLE。
conn sys/tigertger assysdba;--可以連接
即:conn system/tigertiger是以普通的dba的身份登陸的(conn system/tigertiger asdba)
3.權(quán)限比較。sysdba sysoper dba sysdba sysoper startup(啟動(dòng)數(shù)據(jù)庫(kù))startup shutdown shutdown alterdatabaseopen/mount/backup一樣
轉(zhuǎn)變字符集--none createdatabase(創(chuàng)建數(shù)據(jù)庫(kù))--不能
dropdatabase(刪除數(shù)據(jù)庫(kù))--不能
createspfile createspfile alterdatabasearchivelog(歸檔日志)一樣
alterdatabaserecover(恢復(fù)數(shù)據(jù)庫(kù))只能完整恢復(fù)不能不完全恢復(fù)
擁有restricted session會(huì)話(huà)擁有restricted session權(quán)限
可以讓用戶(hù)用為sys用戶(hù)連接可以進(jìn)行一些根本的操作,不能查看用戶(hù)數(shù)據(jù)
登陸之后是sys登陸之后是public
--dba的權(quán)限是登陸之后才有的對(duì)數(shù)據(jù)庫(kù)的操作
4.數(shù)據(jù)庫(kù)管理員的工作
1).顯示初始化參數(shù),200多個(gè)初始化參數(shù)
show parameter命令,在init.ora文件中去D:\oracle\srvm\admin\init.ora 5.數(shù)據(jù)庫(kù)表的邏輯備份與恢復(fù)
邏輯備份是指使用工具export將數(shù)據(jù)對(duì)象的結(jié)構(gòu)和數(shù)據(jù)導(dǎo)出到文件的過(guò)程,邏輯
恢復(fù)是指當(dāng)數(shù)據(jù)庫(kù)對(duì)象被誤操作而破壞后使用工具import應(yīng)用備份的文件把數(shù)據(jù)
對(duì)象導(dǎo)入到數(shù)據(jù)庫(kù)的過(guò)程。物理備份即可在數(shù)據(jù)庫(kù)的open的狀態(tài)下進(jìn)行也可以
在封閉數(shù)據(jù)庫(kù)落后行,但是邏輯備份和恢復(fù)在open的狀態(tài)下進(jìn)行(即數(shù)據(jù)庫(kù)翻開(kāi)時(shí)進(jìn)行)。
--導(dǎo)出分三品種型:
導(dǎo)出表,導(dǎo)出方案,導(dǎo)出數(shù)據(jù)庫(kù)三種方式
導(dǎo)出使用exp命令來(lái)完成的,該命令常用的選項(xiàng)有:
userid:用于指定執(zhí)行導(dǎo)出操作的用戶(hù)名,口令,連接字符串
tables:用于指定履行導(dǎo)出操作的表
owner:用于指定執(zhí)行導(dǎo)出操作的方案
full=y:用于指定執(zhí)行導(dǎo)出操作的數(shù)據(jù)庫(kù)
inctype:用于指定執(zhí)行導(dǎo)出操作的增量類(lèi)型
file:用于指定導(dǎo)出文件名
一.導(dǎo)出表
1.導(dǎo)出本人的表,進(jìn)到oracle裝置的bin目錄下,D:\oracle\BIN再執(zhí)行以下的命令
exp userid=scott/tigertiger@orcl tables=(emp,dept)file=d:\e1.dmp 2.導(dǎo)出其它方案的表
如果用戶(hù)要導(dǎo)出其它方案的表,則需要dba的權(quán)限或是
exp_full_database的權(quán)限,比方system就可以導(dǎo)出scott的表
exe userid=system/tiger@orcl tables=(scott.emp)file=d:\e2.dmp
--scott.emp--哪一個(gè)計(jì)劃的表
3.導(dǎo)出表結(jié)構(gòu)
exp userid=scott/tiger@orcl tables=(emp)file=d:\e3.dmp rows=n
導(dǎo)出大表的構(gòu)造,數(shù)據(jù)量大的時(shí)候exp userid=scott/tiger@orcl tables=(emp)file=d:\e3.dmp direct=y
三.導(dǎo)出方案
導(dǎo)出方案是支使用export工具導(dǎo)出一個(gè)方案或是多個(gè)方案中的所有對(duì)象(表,索引,束縛)
和數(shù)據(jù),并存放到文件中。
1).導(dǎo)出自己的方案
exp scott/tiger@orcl owner=scott file=d:\scott.emp 2).導(dǎo)出其它方案
exp_full_database的權(quán)限,例如system用戶(hù)就能夠?qū)С鋈魏畏桨?BR> exp system/tiger@orcl owner=(system,scott)file=d:\system.dmp 4.導(dǎo)出數(shù)據(jù)庫(kù)
exp userid=system/tiger@orcl full=y inctype=completefile=d:/aa.dmp
二.導(dǎo)入表
1).導(dǎo)入自己表
imp userid=scott/tiger@orcl tables=(emp)file=d:\x.dmp 2).導(dǎo)入表到其它用戶(hù)
要求該用戶(hù)具有dba權(quán)限,或是imp_full_database imp userid=system/tiger@orcl tables=(emp)file=d:\x.dmp touser=scott 3).導(dǎo)入表的結(jié)構(gòu)
導(dǎo)入表的結(jié)構(gòu)而不導(dǎo)入數(shù)據(jù)
imp userid=scott/tiger@orcl tables=(emp)file=d:\x.dmp rows=n 4).導(dǎo)入數(shù)據(jù)
表已經(jīng)存在,可以只導(dǎo)入表的數(shù)據(jù)
imp userid=scott/tiger@orcl tables=(emp)file=d:\x.dmp ignore=y
--數(shù)據(jù)字典和動(dòng)態(tài)性能視圖
基表:數(shù)據(jù)字典是oracle數(shù)據(jù)庫(kù)中最重要的組成局部,它供給了數(shù)據(jù)庫(kù)的一些系統(tǒng)信息--存放靜態(tài)信息
動(dòng)態(tài)性能視圖:動(dòng)態(tài)性能視圖記錄了例程啟動(dòng)后的相干信息.--存入常常變化的動(dòng)態(tài)信息
數(shù)據(jù)字典重要用于取得數(shù)據(jù)庫(kù)信息,用戶(hù)一般不能去操作它
--user_tables:當(dāng)前用戶(hù)領(lǐng)有的所有的表
select table_name from user_tables;
--all_tables當(dāng)前用戶(hù)可以訪問(wèn)的所有的表,不僅自己的表,別人的表,只有
我能拜訪,也能查出來(lái)
select table_name from all_tables;
--dba_tables數(shù)據(jù)庫(kù)中所有的表
select table_name from dba_tables;--表或視圖不存在,由于你沒(méi)有權(quán)限
以sys/tiger asdba;這個(gè)身份可以查看了
--數(shù)據(jù)字典和動(dòng)態(tài)性能視圖
用戶(hù)名,權(quán)限,角色
在建立用戶(hù)時(shí),oracle會(huì)把用戶(hù)的信息存放到數(shù)據(jù)字典中,當(dāng)給用戶(hù)
受權(quán)或是角色時(shí),oracle會(huì)將權(quán)限跟角色的信息放到數(shù)據(jù)字典中
1.通過(guò)查詢(xún):dba_users可以顯示所有的數(shù)據(jù)庫(kù)用戶(hù)具體信息
select username from dba_users;--把所有的用戶(hù)都列出來(lái)了
select username,passwordfrom dba_users;--把所有的用戶(hù)都列出來(lái)了
--密碼是加密的
2.通過(guò)查詢(xún)數(shù)據(jù)字典視圖dba_sys_privs,可以顯示用戶(hù)所具有的系統(tǒng)權(quán)限
select*from system_privilege_map orderbyname;
select username from dba_users;--把所有的用戶(hù)都列出來(lái)了
3.通過(guò)查詢(xún)數(shù)據(jù)字典視圖dba_tab_privs可以顯示用戶(hù)具備的對(duì)象權(quán)限
selectdistinctprivilegefrom dba_tab_privs;
4.通過(guò)查詢(xún)字典dba_col_privs可以顯示用戶(hù)具有的列權(quán)限
5.通過(guò)查詢(xún)數(shù)據(jù)字典視圖dba_role_privs可以顯示用戶(hù)所擁有的的角色
select*from dba_role_privs where grantee='SCOTT';
--角色和權(quán)限,一個(gè)角色里面有良多的權(quán)限,
6.查問(wèn)數(shù)據(jù)庫(kù)的表空間
select tablespace_name from dba_tablespaces;
7.查詢(xún)oracle所有的角色,正常是dba.即:oracle空間有多少種角色
select*from dba_roles;
8.如何查詢(xún)一個(gè)角色所含的權(quán)限?
實(shí)在這里面包含了:一個(gè)角包含的系統(tǒng)權(quán)限
select*from dba_sys_privs where grantee='DBA';
select*from dba_sys_privs where grantee='CONNECT';
一個(gè)角色包括的對(duì)象權(quán)限
select*from dba_tab_privs where grantee='DBA';
--表空間
表空間是數(shù)據(jù)庫(kù)的邏輯組成部門(mén),從物理上講,數(shù)據(jù)庫(kù)存放在
數(shù)據(jù)文件中,從邏輯上講,數(shù)據(jù)庫(kù)則是寄存在表空間中的,表空間
由一個(gè)或是多個(gè)數(shù)據(jù)文件組成.
表空間,數(shù)據(jù)文件,表的關(guān)聯(lián)?
表相當(dāng)于人,表空間相當(dāng)于成都這個(gè)地方,數(shù)據(jù)文件相當(dāng)于人的棲身地
--表空間,段,區(qū),塊(由大到小)
畫(huà)個(gè)方格(表空間),豎分三段(段),每段橫分三段(區(qū)),再把最小段分三段(塊)
國(guó)度,省,市,縣,鎮(zhèn),鄉(xiāng),社。
Oracle中的表空間是沒(méi)有限度的.--表空間
表空間是數(shù)據(jù)庫(kù)的邏輯組成部分,從物理上講,數(shù)據(jù)庫(kù)存放在
數(shù)據(jù)文件中,從邏輯上講,數(shù)據(jù)庫(kù)則是存放在表空間中的,表空間
由一個(gè)或是多個(gè)數(shù)據(jù)文件組成.
表空間,數(shù)據(jù)文件,表的關(guān)系?
表相稱(chēng)于人,表空間相當(dāng)于成都這個(gè)處所,數(shù)據(jù)文件相稱(chēng)于人的寓居地
--表空間,段,區(qū),塊(由大到小)
表空間的作用:
1).把持?jǐn)?shù)據(jù)庫(kù)占用的磁盤(pán)空間
2).dba可以將不同的數(shù)據(jù)類(lèi)型安排到不同的地位,這樣有利于
進(jìn)步i/o性能,同時(shí)利于備份和恢復(fù)等管理操作。
--建立表空間
建立表空間是使用create tablespace命令來(lái)實(shí)現(xiàn)的,須要留神的是
,普通情形下,建立表空間是特權(quán)或是dba來(lái)執(zhí)行的,假如用其它用戶(hù)來(lái)創(chuàng)建
表空間,則用戶(hù)必需有create tablespace的系統(tǒng)權(quán)限
--建立數(shù)據(jù)庫(kù)表空間
在建立數(shù)據(jù)庫(kù)后,為便于管理表,最好建立自已的表空間
createtablespace data01datafile'd:\test01.dbf'
size 20m uniformsize 128k
--說(shuō)明:執(zhí)行完上述命令后,會(huì)建揚(yáng)名稱(chēng)為data01的表空間,
并為該表空間建立名稱(chēng)為data01.dbf的數(shù)據(jù)庫(kù)文件,區(qū)的大小為
128k,
使用數(shù)據(jù)表空間
createtable mypart(
deptno number(5),
dname varchar2(10),
loc varchar2(15)
)tablespace data01;--當(dāng)初就使用表空間了
select*from mypart;
insertinto mypart values(10,'hello','成都');
改變表空間的狀態(tài)
當(dāng)建破表空間時(shí),表空間處于聯(lián)機(jī)(online)狀況,此時(shí)該表空間
是可以訪問(wèn)的,并且該表空間是可以讀寫(xiě)的,即可以查詢(xún)?cè)摫砜臻g的數(shù)據(jù)
,而且還可以在表空間執(zhí)行各種語(yǔ)句。但是在進(jìn)行系統(tǒng)維護(hù)或是
數(shù)據(jù)保護(hù)時(shí),可能需要改變表空間的狀態(tài)。一般情況下,由特權(quán)
用戶(hù)或是dba來(lái)操作
1).使表空間脫機(jī)
altertablespace表空間名offline 2).使表空間聯(lián)機(jī)
altertablespace表空間名online 3).只讀表空間
當(dāng)建立表空間時(shí),表空間可以讀寫(xiě),如果不盼望該表空間上
執(zhí)行update,delete,insert操作,那么可以將表空間修正為
只讀:
altertablespace表空間名readonly altertablespace data01readonly--這個(gè)表中的數(shù)據(jù)不能修了
4).顯示表空間中所有的表
select*from all_tables where tablespace_name='DATA01';
結(jié)果:1SCOTT MYPART DATA01 5).曉得表名,查看該表屬于哪個(gè)表空間
select tablespace_name美國(guó)留學(xué),table_name from user_tables where table_name='EMP';--結(jié)果:表空間:users,表名:EMP select tablespace_name,table_name from user_tables where table_name='MYPART';
6).刪除表空間
一般情況下,由特權(quán)用戶(hù)或是dba來(lái)操作,如果是其它用戶(hù)操作
那么要求用戶(hù)存在drop tablespace系統(tǒng)權(quán)限
droptablespace'表空間'includingcontentsanddatafiles;
說(shuō)明:including contents表示刪除表空間時(shí),刪除該空間的所有的
數(shù)據(jù)庫(kù)對(duì)象,而datafiles表示將數(shù)據(jù)庫(kù)文件也刪除.
7).擴(kuò)展表空間
表空間是由數(shù)據(jù)文件組成的,表空間的大小實(shí)際上就是數(shù)據(jù)文件相加
后的大小,那么我們可以設(shè)想,假設(shè)表employee存放到data01表空間上
,初始大小就是2m,當(dāng)數(shù)據(jù)滿(mǎn)2m空間后,如果在向employee表插入
數(shù)據(jù),這樣就會(huì)顯示空間不足的過(guò)錯(cuò).
案例闡明:
一,樹(shù)立一個(gè)表空間sp001 createtablespace demo01datafile'd:\demo01.dbf'
size 10m uniformsize--dba才行
二,在該表空間上建立一個(gè)普通表mydment其結(jié)構(gòu)和dept一樣
createtable demoemp asselect*from emp where 1=2;
select*from demoemp;
三,向該表中加入一數(shù)據(jù)
insertinto demoemp(select*from emp);
select*from demoemp;--這樣持續(xù)插入,確定會(huì)把數(shù)據(jù)庫(kù)整爆
四,當(dāng)必定時(shí)候就會(huì)呈現(xiàn)無(wú)奈擴(kuò)大的問(wèn)題,怎么辦?
五,就擴(kuò)展表空間,為其增添更多的存儲(chǔ)空間,有三種方式:
1).增加數(shù)據(jù)文件
altertablespace sp01adddatafile'd:\test\sp01.dbf'size20m 2).增長(zhǎng)數(shù)據(jù)文件的大小
alterdatabasedatafile'd:\test\sp01.dbf'resize20m;
--這里需要注意的是數(shù)據(jù)文件的大小不要超過(guò)500m 3).設(shè)置文件的自動(dòng)增加
alterdatabasedatafile'd:\test\sp01.dbf'autoextend onnext10m maxsize500m;
關(guān)鍵詞:服務(wù)器數(shù)據(jù)

