毛片在线视频观看,一级日韩免费大片,在线网站黄色,澳门在线高清一级毛片

薈聚奇文、博采眾長(zhǎng)、見(jiàn)賢思齊
當(dāng)前位置:公文素材庫(kù) > 計(jì)劃總結(jié) > 工作總結(jié) > Oracle復(fù)習(xí)題總結(jié)

Oracle復(fù)習(xí)題總結(jié)

網(wǎng)站:公文素材庫(kù) | 時(shí)間:2019-05-29 07:03:52 | 移動(dòng)端:Oracle復(fù)習(xí)題總結(jié)

Oracle復(fù)習(xí)題總結(jié)

緒論:

1、Oracle,甲骨文,1977年開(kāi)始研發(fā),總部位于美國(guó)加州紅木灘市,創(chuàng)始人為L(zhǎng)arryEllison(埃里森)、BobMiner、EdOates

2、Oracle服務(wù)器=實(shí)例+數(shù)據(jù)庫(kù);Oracle實(shí)例=內(nèi)存+后臺(tái)進(jìn)程;

第四章:表空間的創(chuàng)建與刪除

例4.1建立名稱(chēng)為data_ts1的數(shù)據(jù)表空間,大小為50M,區(qū)間統(tǒng)一為128KB大小。

SQL>connsystem/systempwd@orcl

SQL>droptablespacedata_ts1includingconntents;SQL>createtablespacedata_ts1

2tempfile‘%oracle_home%\\database\\data_ts1.dbf’SIZE50MREUSE3uniformsize128K;

例4.2建立名稱(chēng)為temp_ts1的臨時(shí)表空間,使用temp_ts1.dbf文件存放臨時(shí)數(shù)據(jù)。

SQL>connsystem/systempwd@orcl

SQL>droptablespacetemp_ts1includingconntents;SQL>createtemporarytablespacetemp_ts1

2tempfile‘%oracle_home%\\database\\temp_ts1.dbf’size20Mreuse3uniformsize128k;

例4.3創(chuàng)建10號(hào)部門(mén)經(jīng)理用戶(hù)EMP_MGR10,指定該用戶(hù)的數(shù)據(jù)表空間為data_ts1,臨時(shí)表空間為

temp_ts1。授權(quán)該用戶(hù)可以查看SCOTT用戶(hù)下雇員表中的記錄。SQL>connsystem/systempwd@orcl

SQL>dropuseremp_mgr10cascade;

SQL>createuseremp_mgr10identifiedbyemp_mgr10pwd

2defaulttablespacedata_ts1temporarytablespacetemp_ts1;SQL>grantconnecttoemp_mgr10;SQL>connscott/tiger@orcl

4tempfile‘%oracle_home%\\database\\temp_ts1.dbf’size20Mreuse5uniformsize128k;

例4.4創(chuàng)建和應(yīng)用撤銷(xiāo)表空間。

SQL>connsystem/systempwd@orcl

SQL>droptablespaceundo_ts1includingconntents;SQL>createundotablespaceundo_ts1

2datafile‘%oracle_home%\\database\\undo_ts1.dbf’size50Mreuse;例4.5創(chuàng)建大文件表空間,并指定為SCOTT用戶(hù)的默認(rèn)數(shù)據(jù)表空間。

SQL>connsystem/systempwd@orcl

SQL>droptablespacebigfile_ts1includingconntents;SQL>createbigfiletablespacebigfile_ts1

2datafile‘%oracle_home%\\database\\bigfile_ts1.dbf’size50Mreuse;SQL>alteruserscottdefaulttablespacebigfile_ts1;

需要注意的是,大文件表空間的段空間管理不能為手工(MANUAL),只能為自動(dòng)(AUTO)。例4.6調(diào)整數(shù)據(jù)表空間data_ts1的大小。SQL>connsystem/systempwd@orcl

--為表空間data_ts1增加一數(shù)據(jù)文件,大小為1M。SQL>altertablespacedata_ts1

2adddatafile‘%oracle_home%\\database\\data_ts2.dbf’size1M;--重置該數(shù)據(jù)文件大小為2M。SQL>altertablespace

2datafile‘%oracle_home%\\database\\data_ts2.dbf’size2M;

--修改該數(shù)據(jù)庫(kù),允許該文件自動(dòng)擴(kuò)展,每次擴(kuò)展1M,文件最大擴(kuò)展到10M。SQL>alterdatabasedatafile‘%oracle_home%\\database\\data_ts2.dbf’

2autoextendonnext1Mmaxsize10M;例4.7刪除temp_ts1表空間。

SQL>connsystem/systempwd@orclSQL>droptablespacetemp_ts1

2includingcontentsanddatafiles3cascadeconstraints;例4.8回退段創(chuàng)建與刪除。SQL>conn3next5Ksystem/systempwd@orcl4optimal5000KSQL>droprollbacksegment5minextents15undo_ts1_rbs1;6maxextentsSQL>createrollbacksegment100);undo_ts1_rbs1;2tablespaceundo_ts1storage(initial5K

第5章:常用方案對(duì)象類(lèi)型:

表:table索引:index視圖:view序列:sequence用戶(hù):user約束:constraint表空間:tablespace回退段:rollbacksegment同義詞:synonym數(shù)據(jù)庫(kù)鏈接:databaselink聚簇:cluster分區(qū):partition函數(shù)/過(guò)程/包:function/procedure/package觸發(fā)器:trigger類(lèi)型:type約束的類(lèi)型:

NOTNULL:非空約束

check:檢查約束,用于限制該列的取值范圍Unique:唯一性約束,指定某列值不能重復(fù)primarykey:主鍵約束

Foreignkey:外鍵約束,也叫參照完整性約束Ref:定義列對(duì)象的參照關(guān)系References:參照完整性約束

例5.1創(chuàng)建采用系統(tǒng)默認(rèn)存儲(chǔ)參數(shù)值的關(guān)系表。EXA_05_01.SQL例5.2為SCOTT的雇員表emp創(chuàng)建一個(gè)備份表emp_bak。

SQL>connscott/tiger@emp_orclSQL>dorptableemp_bak;SQL>createtableemp_bakSQL>asselect*fromemp;SQL>descemp_bak

SQL>select*fromemp_bak;

例5.3創(chuàng)建表stu2,并指定它的存儲(chǔ)參數(shù)。EXA_05_03.SQL例5.4創(chuàng)建學(xué)生相關(guān)表,在列中定義約束。EXA_05_04.SQL例5.5創(chuàng)建學(xué)生相關(guān)表,在列之外定義約束。EXA_05_05.SQL例5.6創(chuàng)建學(xué)生相關(guān)表,在列之外定義約束。EXA_05_06.SQL

例7.1某電子商務(wù)網(wǎng)站估計(jì)每月產(chǎn)生近千萬(wàn)條訂單記錄。該網(wǎng)站采用年YYYY+月MM+當(dāng)月流水號(hào)nnnnnnnn的形式標(biāo)識(shí)和區(qū)分每一份訂單。當(dāng)有用戶(hù)提交一份訂單時(shí),系統(tǒng)自動(dòng)生成該訂單的編號(hào)并告

知用戶(hù)這個(gè)唯一的訂單號(hào)。創(chuàng)建一序列,用于生成每月的訂單流水號(hào)。(老師要求例子)connscott/tiger@orcl

dropsequenceorder_seq;createsequenceorder_seqincrementby1

startwith10000000cache500nocycle;

colsequence_nameformata13

selectsequence_name,min_value,max_value,increment_by,last_numberfromuser_sequences;

selectorder_seq.currvalfromdual;selectorder_seq.nextvalfromdual;selectorder_seq.currvalfromdual;selectorder_seq.nextvalfromdual;selectorder_seq.currvalfromdual;

--函數(shù)案例:案例1.返回工人年工資。

createorreplacefunctionxxc_fun1(newnamevarchar2)returnnumberisyearSalnumber(10,2);begin

selectsal*12+nvl(comm,0)*12intoyearSalfromempwhereename=newname;returnyearSal;end;

例9.編寫(xiě)函數(shù)按YYYY-MM-DDHH24:MI:SS格式以字符串形式返回當(dāng)前系統(tǒng)時(shí)間。connectscott/tiger@orcl

createorreplacefunctioncurrent_timereturnvarchar2asbegin

returnto_char(sysdate,"yyyy-mm-ddhh24")||":"

||to_char(sysdate,"mi")||":"||to_char(sysdate,"ss");end;/

selectcurrent_timefromdual;

例9.21查詢(xún)指定編號(hào)雇員的名字、工資和傭金。存儲(chǔ)過(guò)程connscott/tiger@orcl

createorreplaceprocedurequery_emp(p_noinemp.empno%type,p_nameoutemp.ename%type,p_saloutemp.sal%type,

p_commoutemp.comm%type)isbegin

selectename,sal,comm

intop_name,p_sal,p_comm

fromemp

whereempno=p_no;endquery_emp;/

variableg_namevarchar2(25)variableg_salnumbervariableg_commnumber

executequery_emp(7369,:g_name,:g_sal,:g_comm)

printg_name

例9.39創(chuàng)建觸發(fā)器:

1.在scott的emp表上建立語(yǔ)句前觸發(fā)器emp_permit_changes。Createorreplacetriggerscott.emp_helloBeforeDeleteorinsertorupdateOnscott.empBegin

raise_application_error(-201*1,"howareyou!");End;2.修改觸發(fā)器

使emp_hello觸發(fā)器不能觸發(fā):altertriggerscott.emp_hellodisable;3.刪除觸發(fā)器

droptriggerscott.emp_hello;end;/

updateempsetsal=100whereempno=7369;

例9.37為雇員表emp創(chuàng)建一觸發(fā)器,確保插入記錄的工資列sal不小于0,同時(shí)新記錄的能高于已有記錄最高工資的2倍。connscott/tiger@orcl

createorreplacetriggercheck_sal_empbeforeinsertorupdateonempreferencingoldasoldnewasnewforeachrowbegin

if:new.sal<0then

raise_application_error(-20501,"雇員工資不能為負(fù)數(shù)");endif;

if:new.sal>2*wage_package3.g_salthen

raise_application_error(-20502,"雇員工資超過(guò)現(xiàn)有最高工資2倍");endif;end;/

insertintoemp(empno,ename,hiredate,job,sal,deptno)values(300,"jordan",sysdate,"it_prog",-3,10);

insertintoemp(empno,ename,hiredate,job,sal,deptno)values(300,"tracyzhou",sysdate,"acc.offi.",16000,10);

Oracle實(shí)例有兩種類(lèi):?jiǎn)芜M(jìn)程實(shí)例和多進(jìn)程實(shí)例。

多進(jìn)程系統(tǒng)中,進(jìn)程分為兩類(lèi):用戶(hù)進(jìn)程和Oracle進(jìn)程。

sal列值不Oracle進(jìn)程又分為兩類(lèi):服務(wù)器進(jìn)程(serverprocess)和后臺(tái)進(jìn)程(backgroundprocess)。

Oracle數(shù)據(jù)庫(kù)的索引模式:

(1)B-樹(shù)索引(2)B-樹(shù)簇索引(3)散列簇索引(4)全局和本地索引(5)反序索引(6)位圖索引(7)基于函數(shù)的索引(8)域索引創(chuàng)建視圖:

1、生成一個(gè)部門(mén)號(hào)是10的視圖:

createviewd10empasselectempno,ename,salfromempwheredeptno=10;2、刪除視圖:dropviewd10emp;3、創(chuàng)建索引:

createindexi_enameonemp(ename);

createuniqueindexi_empnoonemp(empno);索引應(yīng)用

如果查詢(xún)語(yǔ)句如下則沒(méi)有用到索引i_ename:selectename,job,salfromemp;如果查詢(xún)語(yǔ)句如下則用到索引i_ename:selct*fromempwhereename=‘jones’;4、刪除索引:dropindexi_ename;

5、創(chuàng)建一個(gè)用戶(hù):createusermyselfidentifiedbymy;6、修改用戶(hù)口令:alterusermyselfidentifiedbyme;

7、對(duì)象權(quán)限授權(quán):把dept的select對(duì)象權(quán)限授給myself用戶(hù):

grantselectondepttomyself;

把emp的select權(quán)限授給所有用戶(hù):grantselectonemptopublic;8、收回對(duì)象權(quán)限:

從myself收回所有dept的對(duì)象權(quán)限:revokeallondeptfrommyself;收回所有用戶(hù)對(duì)emp的select權(quán)限:revokeselectonempfrompublic;9、刪除用戶(hù):dropusermyself;

實(shí)驗(yàn)三:數(shù)據(jù)插入(insert)、修改update和刪除delete1.用Insert在基本表customer中插入數(shù)據(jù)

SQL>insertintocustomervalues(‘nicholson’,’ca’,6989.99);2.在表STATE中插入指定的字段

SQL>insertintostate(state_name,state_cd)2values(‘massachusetttes’,’MA’);1rowcreated.3.修改數(shù)據(jù)

把state表中newyork改為florida,ny改為fd:

updatestatesetstate_name=‘florida’,state_cd=‘fd’wherestate_name=‘newyork’andstate_cd=‘ny’;4.刪除數(shù)據(jù)

從state表刪除state_name為Florida和state_cd為fd的記錄:deletefromstatewherestate_name=‘florida’andstate_cd=‘fd’;

刪除表全部數(shù)據(jù):deletefromhzx.sc

2、對(duì)s、c、sc表進(jìn)行操作:

s(s#,sname,age,sex)對(duì)應(yīng)的中文為:(學(xué)號(hào),姓名,年齡,性別)]sc(s#,c#,grade)對(duì)應(yīng)的中文為:[學(xué)習(xí)(學(xué)號(hào),課程號(hào),成績(jī))]c(c#,cname,teacher)對(duì)應(yīng)的中文為:[課程(課程號(hào),課程名,任課教師)]1)、把c2課程的非空成績(jī)提高10%。

updatestu.scsetgrade=grade*1.1wherec#="c2"andc#isnotnull;2)、在sc表中刪除課程名為physics的成績(jī)的元組。

deletefromstu.scwherec#="physisc";3)、在s和sc表中刪除學(xué)號(hào)為s8的所有數(shù)據(jù)。

deletefromstu.scwheres#="s8";deletefromstu.swheres#="s8";

實(shí)驗(yàn)四:索引、視圖

1.建立男學(xué)生的視圖,屬性包括學(xué)號(hào)、姓名、選修課程和成績(jī)。

createviewmanasselects.s#,sname,cname,gradefromc,s,scwheresex="m"ands.s#=sc.s#andc.c#=sc.c#;

2.在男學(xué)生視圖中查詢(xún)平均成績(jī)大于80分的學(xué)生學(xué)號(hào)和姓名。selectdistincts#,snamefrommanwheresnamein(

selectsnamefrommangroupbysnamehavingavg(grade)>80);3.撤消生成的視圖。SQL>dropviewman;

4.創(chuàng)建一個(gè)新用戶(hù)newuser。執(zhí)行語(yǔ)句:createusernewuseridentifiedbymy;5.使用grant語(yǔ)句,把對(duì)基本表s、c、sc的使用權(quán)限授給newuser用戶(hù)。grantallonstonewuser;grantallonctonewuser;grantallonsctonewuser;

6.使用revoke語(yǔ)句從newuser手中收回基本表s、c、sc的使用權(quán)。

revokeallonsfromnewuser;revokealloncfromnewuser;revokeallonscromnewuser;

7.刪除用戶(hù)newuser。執(zhí)行語(yǔ)句:dropusernewuser;

8.對(duì)基本表S按照S#生成一個(gè)索引。執(zhí)行語(yǔ)句:CREATEINDEXssONS(S#);9.對(duì)基本表C按照C#生成一個(gè)索引。執(zhí)行語(yǔ)句:CREATEINDEXccONC(C#);10.刪除基本表C建立的索引。執(zhí)行語(yǔ)句:DROPINDEXss;

擴(kuò)展閱讀:oracle復(fù)習(xí)總結(jié)

一、

1.儲(chǔ)存模式是一種包含了諸如段。視圖。過(guò)程。函數(shù)程序包。觸發(fā)器。用戶(hù)自定義的對(duì)象集合類(lèi)型序列同義詞和數(shù)據(jù)連接對(duì)象的邏輯結(jié)構(gòu)。2.用戶(hù)角色,對(duì)象權(quán)限系統(tǒng)權(quán)限

Select,insert,update,delete可以使用的權(quán)限是execute二.SQL語(yǔ)言

1.創(chuàng)建表createtable表名2.約束

(1)非空約束notnull(2)唯一約束unique

(3)主鍵約束primarykey最多只能有一個(gè)主鍵約束主鍵約束可以使用一列組成,不能有重復(fù)的不能為空

(4)外鍵約束foreignkey

外鍵是指引用一個(gè)表中的某個(gè)列或某幾個(gè)列,或本表中另一個(gè)列或者幾個(gè)列被引用的列應(yīng)該是主鍵列或者唯一性約束列。

約束關(guān)鍵詞constraint名稱(chēng)foreignkeyreferences引用表名引用表主鍵(5)檢查約束checkconstraint名稱(chēng)check表達(dá)式(6)缺省約束default3.修改表(1)增加列

Altertable表名add新列名數(shù)據(jù)類(lèi)型(2)更新列

Altertable表名modify列名數(shù)據(jù)類(lèi)型(3)刪除列

Altertable表名dropcolumn要?jiǎng)h除的列名(4)刪除表Droptable表名2.DML

1.檢索所有列Select*fromemp

Selectename,jobfromemp;

Selectename,to_char(hiredate,yyyy-mm-dd)fromempSelectdistinctdeptno,jobfromemp取消重復(fù)行Selectename,sal*12frommep處理null

Selectename,sal,comm.,(sal+comm)fromemp連接字符串

Selectename||isa||jobas”employdetail”fromemp使用簡(jiǎn)單where子句

Selectename,salfromempwheresal>201*

Selectjob,salfromempwhereename=SCOTT;

Selectjob,salfromempwherelower(ename)=scott;

Where子句和betweenand

Selectename,sal,hiredate,jobfromempwheresalbetween1000and201*Where子句中使用like操作符

Selectename,salfromempwhereenamelikeS%;Orderby子句

1,升序排列

Selectename,salfromempwheredeptno=30orderbysal;2.降序排列

Selectename,sal,comm.Fromempwheredeptno=30orderbysaldesc3.使用多列排序

Selectename,sal,commmfromempwheredeptno=30orderbysalasc,comm.Desc4.數(shù)據(jù)分組Gropby1,分組函數(shù)

Selectmax(sal),min(sal)fromemp2,取消重復(fù)值

Selectcount(distinctdeptno)asdistinct_deptfrommep3.groupbyhaving子句

Selectcolumn,group_functionfrom表名whereconditiongroupbygroupby_expressionhavinggroup_condition

使用groupby進(jìn)行單列分組selectdeptno,avg(sal),mac(sal)fromempgroupbydeptno使用groupby進(jìn)行多列分組

Selectdeptno,job,avg(sal),max(sal)fromempgroupbydeptno,job;

使用having子句限制分組顯示selectdeptno,avg(sal),max(sal)fromempgroupbydeptnohavingavg(sal)ename=SMITH)成對(duì)比較

Selectename,sal,comm.,deptnofromempwhere(sal,nvl(comm.,-1))in(selectsal,nvl(comm.,-1)fromempwheredeptno=30)4.合并查詢(xún)

Union并集走掉結(jié)果集中的重復(fù)行unionall兩個(gè)結(jié)果記的并集不會(huì)取消重復(fù)行intersect兩個(gè)結(jié)果集的交集minus兩個(gè)結(jié)果集的差集Insert

(1)插入單行數(shù)insertintotablecolumn1coulmn2valuesvalues1values2

不使用列插入單行數(shù)據(jù)

Insertintodeptvalues(50,TRAINBOSTON)使用列插入單行數(shù)據(jù)

Insertintoemp(emp,ename,jobhiredate)values(1244,john,clerk,01-3-86)使用子查詢(xún)插入數(shù)據(jù)

Insertintoemployee(empno,ename,sal,deptno)selectempno,enmae,sal,deptnofromempwheredeptno=20使用first

Selectfirstwhendeptno=10thenintodept10whendeptno=20thenintodept20elseintootherselect*fromemp555update2.3事務(wù)鎖

事務(wù)用于確保數(shù)據(jù)庫(kù)的一致性主要由insertupdatedeleteselect。。。。forupdate提交事務(wù)commit回退事務(wù)rollback三.?dāng)?shù)據(jù)庫(kù)對(duì)象1,同義詞

Createsynonym名字forobject_name2序列創(chuàng)建序列

Createsequence名字Startwith名字incrementby數(shù)字(初始值)maxvalue數(shù)字cycle和nocycle使用序列

Selects_test.nextvalfromdualSelects_test.currvalformdual使用序列填充主鍵Creaetetablestudent(

Idintegerconstraints_testprimarykey,Namevarchar2(20);

Insertintostudent(id,name)values(s_test.nextval,fendou)3.視圖

1.視點(diǎn)集2.簡(jiǎn)化操作3.定制數(shù)據(jù)4.合并分割數(shù)據(jù)5.安全性4.創(chuàng)建并使用視圖

Createorreplaceviewview_nameassubqueryconstranintconstraint_name

Createviewemp_viewasselectempno,ename,deptnofromempwheredeptno=30Insertintoemp_viewvalues(201*,fendou,30)創(chuàng)建具有checkoption約束的視圖Creaeteorreplaceemp_viewasselectempno,ename,deptnofromempwheredeptno=30wiehcheckoptionconstraintemp_view_ck5.索引

索引加快數(shù)據(jù)的一種有效方式

Creaeteuniqueindexindex_nameontable_namecolumn_name(column_name…)Tablespacetablespace_name

Createindexi_emp_indexonemp(deptno)

Createendexi_emp_ednoonemp(empno,deptno)修改索引

Alterindexi_emp_ednorenametoi_emp_noDropindexi_emp_no;臨時(shí)表

Createglobaltemporary表名列類(lèi)型Oncommitpreserverows會(huì)話(huà)中斷時(shí)Commit時(shí)

Createglobaltemporarytabletemp_test2(tempIdint)

Oncommitdeleterows;四.PLSQL編程簡(jiǎn)介1,塊結(jié)構(gòu)Declare

名稱(chēng)類(lèi)型值Begin

執(zhí)行異常處理部分End

已知矩形面積和高求寬度DeclareV_widthint;V_heithtint:=2;V_areaint:=6;Begin

SetthewidtheaualtotheareadividedbytheheightV_width:=v_area/v_height;

Dbms_output.put_line(“v_width=”||v_width);Exception

Whenzero_dividethen

Dbms_output.put_line(divisonbyzero);End

2,變量和類(lèi)型

Intvarchar2number條件邏輯

Ifthenelseelseifendif循環(huán)

While循環(huán)for循環(huán)簡(jiǎn)單循環(huán)Loop

StatementsEndloop

While循環(huán)

友情提示:本文中關(guān)于《Oracle復(fù)習(xí)題總結(jié)》給出的范例僅供您參考拓展思維使用,Oracle復(fù)習(xí)題總結(jié):該篇文章建議您自主創(chuàng)作。

來(lái)源:網(wǎng)絡(luò)整理 免責(zé)聲明:本文僅限學(xué)習(xí)分享,如產(chǎn)生版權(quán)問(wèn)題,請(qǐng)聯(lián)系我們及時(shí)刪除。


Oracle復(fù)習(xí)題總結(jié)》由互聯(lián)網(wǎng)用戶(hù)整理提供,轉(zhuǎn)載分享請(qǐng)保留原作者信息,謝謝!
鏈接地址:http://www.seogis.com/gongwen/671834.html
相關(guān)文章