277 downloads
271 Views
234KB Size
Report
This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Report copyright / DMCA form
FBGBKL?JKL:JKLGHC F:L?F:LBDB B F?O:GBDB D:N?>J: F:L?F:LBQ?KDH=H H;?KI?Q?GBY W
F_lh^bq_kdb_fZl_jbZeudki_pdmjkm ³JZkij_^_e_ggu_[Zau^ZgguogZijbf_j_ORACLE” ^eyklm^_glh\dmjkZ^g_\gh]hhl^_e_gby KhklZ\bl_evBN:klZoh\Z
1
F_lh^bq_kdb_fZl_jbZeuj_dhf_g^m_lkybkihevah\Zlv^eyijh\_^_gby e_dpbhgguobeZ[hjZlhjguoaZgylbcihki_pdmjkmgZdmjk_^g_\gh]hhl^_ e_gby³JZkij_^_e_ggu_[Zau^ZgguogZijbf_j_ORACLE”. <f_lh^bq_kdbo fZl_jbZeZo jZkkfZljb\Zxlky Zjobl_dlmjZ wda_fieyjZ ORACLE hibkZgb_ hkgh\guoh[t_dlh\bwe_f_gluijh]jZffbjh\ZgbygZyaud_KM;>ORACLE. F_lh^bq_kdb_ fZl_jbZeu jZkkqblZgu gZ klm^_glh\ ^g_\gh]h b \_q_jgbo hl^_e_gbcZkibjZglh\fZ]bkljh\bgZgZmqguojZ[hlgbdh\aZgbfZxsboky jZajZ[hldhcijbeh`_gbc^eyjZkij_^_e_gguo[Za^ZgguokihfhsvxKM;> ORACLE.
J_p_ga_glu ^lgaZ\dZnl_ogbq_kdhcdb[_jg_lbdbbZ\lhfZlbq_kdh]h j_]mebjh\Zgby<=MEha]Zq_\=B AZf^bj_dlhjZnbebZeZA:H³Kl_jebg]J =jmiK:´\]
I_qZlZ_lkyihj_r_gbxj_^Zdpbhggh]hKh\_lZnZdmevl_lZijbdeZ^ghc fZl_fZlbdbbf_oZgbdb
:klZoh\ZBjbgZN_^hjh\gZ
2
JZkij_^_e_ggu_[Zau^ZgguoORACLE) GZ g_dhlhjh_ \j_fy aZ[m^_f h l_ogbq_kdbo kj_^kl\Zo h[kem`b\Zx sbo l_ogheh]bx deb_gl-k_j\_j \ dhlhjhc k_j\_j \uklmiZ_l dZd ma_e eh dZevghc \uqbkebl_evghc k_lb Ehkms_kl\eyxlkyhi_jZpbbih^hklmimbhl[hjm^ZgguoIh^jZkij_^_ e_gghc;>ihgbfZxlojZg_gb_h[uqguolZ[ebpbeb^Z`_qZkl_clZ[ebp\ jZaebqguomaeZoE
KljmdlmjZwda_fieyjh\ Oracle
Wda_fieyj Oracle -keh`gucdhfie_dkkljmdlmjiZfylbbijhp_kkh\hi_ jZpbhgghc kbkl_fu jbk DZ`^Zy ;> Oracle bf__l k\yaZgguc k g_c wd a_fieyjHj]ZgbaZpbywda_fieyjZiha\hey_lKM;>h[kem`b\Zlvfgh`_kl\h lbih\ ljZgaZdpbc [_ki_qb\Zlv \ukhdmx ijhba\h^bl_evghklv p_ehklghklv ^Zgguo b [_ahiZkghklv L_jfbg ijhp_kk hagZqZ_l ex[mx aZ^Zqm \uihe gy_fmx[_a\f_rZl_evkl\Zihevah\Zl_ey. Hldjulb_;> Oracle\dexqZ_lljbklZ^bb 1. Nhjfbjh\Zgb_wda_fieyjZ Oracle ij_^mklZgh\hqgZyklZ^by 2. MklZgh\dZ[Zau^Zgguowda_fieyjhfmklZgh\hqgZyklZ^by 3. Hldjulb_;>klZ^byhldjulby Wda_fieyj \dhlhjhfg_l[Zau^ZgguogZau\Z_lkyg_aZgyluf (idle gh hg aZgbfZ_liZfylvbg_\uihegy_lgbdZdhcjZ[hluWda_fieyjfh`_lih^ kh_^bgblvkylhevdhdh^ghc;>Z^hl_oihjihdZg_[m^_lbkihevah\Zg Par-
3
allel Server,;>fh`_l[ulvih^dexq_gZlhevdhdh^ghfmwda_fieyjm Oracle. Wda_fieyj — wlhfha]kbkl_fuh[jZ[hldb^Zgguo<wda_fieyj_\uihegy xlky\k_hi_jZpbb\lh\j_fydZd\;>ojZgylky\k_^Zggu_ ;hevrbgkl\h gZkljh_d wda_fieyjZ k\yaZgh k dhfihg_glZfb \ ]eh[Zevghc kbkl_fghch[eZklbGhdjhf_gbokms_kl\mxlbg_dhlhju_hipbbgZkljhcdb dZkZxsb_kynhgh\uoijhp_kkh\ =eh[ZevgZykbkl_fgZyh[eZklv <SGA ojZgylkykljmdlmjuiZfylbg_h[oh^bfu_^eyfZgbimebjh\Zgby ^ZggufbZgZebaZij_^eh`_gbc SQLbdwrbjh\ZgbyljZgaZdpbcDwlhch[ eZklbh^gh\j_f_gghbf__l^hklmifgh`_kl\hijhp_kkh\dhlhju_fh]mlkqb lu\Zlv ^Zggu_ bag__bebfh^bnbpbjh\Zlvbobkihev amxl bgnhjfZpbx gZoh^ysmxky \ SGA. SGA \u^_ey_lky kjZam `_ ihke_ kha^Zgby wda_fieyjZ _s_ gZ ij_^mklZgh\hqghc klZ^bb Hk\h[h`^Z_lky wlZ h[eZklvlhevdhihke_ihegh]h\udexq_gbywda_fieyjZ Wda_fieyj Oracle ij_^klZ\ey_l kh[hc keh`gucdhfie_dk\aZbfh^_ckl \mxsboijhp_kkh\ SGAkhklhblbake_^mxsbodhfihg_glh\ •jZa^_ey_fucime (Shared Pool); •dwr-[mn_j^Zgguo (Database Buffer Cache); •[mn_j`mjgZeZljZgaZdpbc (Redo Log Buffer); •kljmdlmjuk_j\_jZfgh]haZ^Zqghckj_^u (Multi-Threaded Server — MTS). JZa^_ey_fucime JZa^_ey_fuc ime jbk kh^_j`bl dwr [b[ebhl_db dwr keh\Zjy b mijZ\eyxsb_kljmdlmjuk_j\_jZ lZdb_dZdgZ[hjkbf\heh\;> Dwr[b[ ebhl_dbojZgblieZg\uiheg_gbyij_^eh`_gbc SQLA^_kvkh^_j`ZlkyaZ]h eh\dbiZd_lh\ PL/SQLbijhp_^mj\uihegy\rbokyjZg__Dwrkeh\ZjyojZ gbl kljhdb keh\Zjy ^Zgguo dhlhju_ [ueb bkihevah\Zgu ^ey e_dkbq_kdh]h ZgZebaZ ij_^eh`_gbc SQL. K_j\_j Oracle bkihevam_l dwr [b[ebhl_db ^ey ih\ur_gbykdhjhklb\uiheg_gbyhi_jZlhjh\ SQL. JZaf_jjZa^_ey_fh]himeZaZ^Z_lkyiZjZf_ljhf SHARED POOL SIZE\ nZce_ init.ora.JZaf_jghklvagZq_gbyiZjZf_ljZ —[ZcluG_h[oh^bfhaZdZ au\Zlvh[t_fimeZ Dwr-[mn_j^Zgguo Dwr-[mn_j ^Zgguo khklhbl ba [ehdh\ iZfylb lh]h `_ jZaf_jZ qlh b [ehdb Oracle.i_j\uf^_ehfaZ]jm `Zxlky\dwr-[mn_j<wlbo`_[ehdZoiZfylb\uihegy_lkybex[h_h[gh\ e_gb_^ZgguoIhwlhfmhq_gv\Z`ghijZ\bevghmklZgh\blvjZaf_j[mn_jZ KM;>i_j_ghkbl^Zggu_gZ^bkd —\khhl\_lkl\bbkihjy^dhfbojZa f_s_gby \ kibkd_ LRU (Least Recently Used). Wlhl kibkhd hlke_`b\Z_l h[ jZs_gb_d[ehdZf^Zgguobmqblu\Z_lqZklhlmh[jZs_gbc?keb\uihegy_l kyh[jZs_gb_d[ehdm^ZgguoojZgys_fmky\dwr-[mn_j_lhihf_sZ_lky\ lhldhg_pkibkdZdhlhjucghkblgZa\Zgb_ MRU (Most Recently Used).?keb k_j\_jmlj_[m_lkyf_klh\dwr-[mn_j_^eyaZ]jmadbgh\h]h[ehdZlhhgj_4
Jbk rZ_l wlhl fhf_gl k ihfhsvx kibkdZ LRU dZdhc ba [ehdh\ i_j_g_klb gZ ^bkdqlh[uhk\h[h^blvf_klh^eygh\h]h;ehdbgZb[he__hlklhysb_\kib kd_hl MRU -dZg^b^ZlugZm^Ze_gb_badwr-[mn_jZLZdbfh[jZahf^hevr_ \k_]h hklZxlky \ dwr-[mn_j_ l_ [ehdb d dhlhjuf qZs_ \k_]h \uihegy_lky h[jZs_gb_Fh^bnbpbjh\Zggu_[ehdbgZau\Zxlky]jyagufb (dirty)bihf_ sZxlky\khhl\_lkl\mxsbc dirty-kibkhd ;mn_j`mjgZeZljZgaZdpbc >Zggu_hljZgaZdpbyoojZgylky\wlhf[mn_j_^hl_oihjihdZg_[m ^ml i_j_ibkZgu \ nZce hi_jZlb\gh]h `mjgZeZ ljZgaZdpbc Ihke_ aZiheg_ gby[mn_jZ_]hkh^_j`bfh_i_j_ghkblky\nZce`mjgZeZljZgaZdpbc JZaf_j [mn_jZ `mjgZeZ ljZgaZdpbc aZ^Z_lky iZjZf_ljhf LOG_BUFFER.AgZq_gb_iZjZf_ljZmdZau\Z_ljZaf_j[mn_jZ\[ZclZo < j_amevlZl_ \u ihemqbl_ \j_fy dhlhjh_ ihevah\Zl_evkdb_ ijhp_kku gZoh^bebkv \ khklhygbb h`b^Zgby ijb h[jZs_gbb d [mn_jm `mjgZeZ ljZg aZdpbc Nhgh\u_ijhp_kku Oracle <ijhp_kk_jZ[hluKM;> OracleijhkfZljb\Z_llukyqbaZibk_c\lZ[ ebpZo^Zgguohl\_qZ_lgZkhlgbaZijhkh\ihevah\Zl_e_ch^gh\j_f_ggh
5
• LGWR, • ARCH, • KDJL, • RECO, • SPUn, • Dnnn, -LCKn LZd`_gm`ghh[jZlblv\gbfZgb_gZijhp_kku Userb Server,\uihegyxsb_ h[jZ[hldmljZgaZdpbcbijhp_kku Parallel Query (Pnnn),dhlhju_hl\_lkl\_g guaZh[jZ[hldmiZjZee_evguoaZijhkh\Ohlywlbijhp_kkubg_d\Zebnbpb jmxlky dZd nhgh\u_ hgb b]jZxl agZqbl_evgmx jhev \ nmgdpbhgbjh\Zgbb kbkl_fu Ijhp_kkuPMONbSMON \uihegyxl Z\lhfZlbq_kdmx ³m[hjdm´ ihke_ \g_aZigh ij_djZlb\rboky beb aZ\_jrb\rboky Z\Zjbcgh ijhp_kkh\ Ihke_aZimkdZ;>ijhp_kkSMON\uihegy_lZ\lhfZlbq_kdh_\hkklZgh\e_gb_ wda_fieyjZ?kebijbihke_^g_f\udexq_gbb;>qlh-eb[hg_[uehaZ\_jr_ gh SMONZ\lhfZlbq_kdbaZimkdZ_lg_aZ\_jr_ggu_hi_jZpbb PMON - Process MonitorFhgblhjijhp_kkh\ \uihegy_lZ\lhfZlbq_ kdmxm[hjdmihke_\g_aZighij_djZlb\rbokybebaZ\_jrb\rbokyZ\Zjbcgh ijhp_kkh\WlZm[hjdZ\dexqZ_lm^Ze_gb_k_ZgkZ[ehdbjh\hddhlhju_[u eb bf mklZgh\e_gu g_ijbgyluo ljZgaZdpbc hk\h[h`^_gb_ j_kmjkh\ ]eh [Zevghckbkl_fghch[eZklb\u^_e_gguowlhfmijhp_kkm Nhgh\u_ijhp_kku SMONb PMON^he`gu[ulvg_ij_f_gghaZims_guijbaZimkd_kbkl_fu< ijhlb\ghfkemqZ_kbkl_fZnmgdpbhgbjh\Zlvg_[m^_l Ijhp_kk DBWR - Database Writer —hl\_qZ_laZi_j_ghkh[gh\e_gguo [ehdh\ aZg_k_gguo \ dirty-cibkhd ba dwr-[mn_jZ ^Zgguo \ nZceu ^Zgguo Oracle.Wlhlijhp_kkhl\_qZ_laZi_j_ aZibkv bgnhjfZpbb ba [mn_jZ `mjgZeZ ljZgaZdpbc dhlhjuc gZoh^blky \ ]eh[Zevghc kbkl_fghc h[eZklb \ nZceu hi_jZlb\gh]h `mjgZeZ Oracle g_ kqblZ_l ljZgaZdpbx \uiheg_gghc ^h l_o ihj ihdZ ijhp_kk LGWR g_ i_j_aZibr_l^Zggu_hg_cba[mn_jZ`mjgZeZljZgaZdpbc\nZceWlhlijhp_kk j_^dhkem`blijbqbghchkeh`g_gbc\jZ[hl_ Ijhp_kku-^bki_lq_ju Ijhp_kku k_j\_jZ fh]ml [ulv eb[h aZdj_ie_gu aZ hij_^_e_ggufb ihevah\Zl_evkdbfbijhp_kkZfbeb[hbkihevah\Zlvkyfgh]bfbihevah\Zl_ev kdbfbijhp_kkZfbkh\f_klgh<ihke_^g_fkemqZ_hgbgZau\ZxlkyjZa^_ey_ fufb ijhp_kkZfb beb k_j\_jZfb Ijb bo bkihevah\Zgbb \ kbkl_f_ ^he`_g
6
kms_kl\h\Zlv dZd fbgbfmf h^bg ijhp_kk – ^bki_lq_j Bo fh`_l [ulv b [hevr_\aZ\bkbfhklbhlhi_jZpbhgghckj_^u Ijhp_kkARCH hl\_qZ_laZdhibjh\Zgb_iheghklvxaZiheg_ggh]hhi_ jZlb\gh]h`mjgZeZljZgaZdpbc\Zjob\gu_nZceu`mjgZeh\ljZgaZdpbcDh]^Z\hagbdZ_lih^hajbl_evgZyljZgaZdpby RECO \uihegy_l k\hb nmgdpbb Z\lhfZlbq_kdb [_a \f_rZl_evkl\Z Z^fbgbkljZlhjZ;> Ijhp_kk SNPn \uihegy_l Z\lhfZlbq_kdb_ h[gh\e_gby kgbfdh\ b aZ imkdZ_lijhp_^mju\khhl\_lkl\bbkjZkrbj_gb_f LCKn –iha\hey_l\kj_^_kiZjZee_evgufh[kem`b\Zgb_fdh^ghc;> h[jZsZlvky fgh`_kl\m wda_fieyjh\ Oracle. GZ wlhl ijhp_kk \haeZ]Z_lky hl\_lkl\_gghklv aZ dhhj^bgZpbx [ehdbjh\hd mklZgZ\eb\Z_fuo jZagufb wda_fieyjZfb ?keb g_l ijhp_kkZ iZjZee_evgh]h h[kem`b\Zgby lh g_h[oh^bfhklv\wlhfijhp_kk_hliZ^Z_l Ijhp_kku iZjZee_evguo aZijhkh\ ihemqbeb \ kbkl_f_ gZbf_gh\Zgb_ Pnnn.K_j\_j OracleaZimkdZ_lbhklZgZ\eb\Z_lijhp_kku Pnnn\aZ\bkbfhklb hlZdlb\ghklbjZ[hluk;>bgZkljhcdbhipbciZjZee_evguoaZijhkh\Wlb ijhp_kkuijbgbfZxlmqZklb_\nhjfbjh\Zgbbbg^_dkh\lZ[ebpbaZijhkh\ Dhebq_kl\h aZimkdZ_fuo ijhp_kkh\ hij_^_ey_lky ^\mfy iZjZf_ljZfb PARALLEL MIH SERVERS b PARALLEL_MAX SERVERS, hij_^_eyxsbfbkhhl\_lkl\_gghfbgbfZevgh_bfZdkbfZevgh_dhebq_kl\haZ imkdZ_fuoijhp_kkh\ Ijhp_kkuihevah\Zl_eybk_j\_jZ Ijbeh`_gby b mlbeblu k\yau\Zxlky k KM;> ihkj_^kl\hf ijhp_kkh\ ihevah\Zl_ey DZ`^uc ijhp_kk ihevah\Zl_ey ih^dexqZ_lky d ijhp_kkm k_j \_jZ Ijhp_kk k_j\_jZZgZebabjm_lb\uihegy_li_j_^Zggu__fmhi_jZlhju SQL b \ha\jZsZ_l j_amevlZl ijhp_kkm ihevah\Zl_ey Djhf_ lh]h ijhp_kk k_j\_jZ kqblu\Z_l [ehdb ^Zgguo ba nZceh\ ^Zgguo b jZaf_sZ_l bo \ dwr[mn_j_^Zgguo
Hkgh\gu_h[t_dluKM;>ORACLE
Oracleih^^_j`b\Z_lj_eypbhggmxfh^_ev^Zgguoihwlhfm_kl_kl\_g gh qlh d qbkem hkgh\guo h[t_dlh\ Oracle hlghkylky lZ[ebpZ ij_^klZ\e_ gb_yihevah\Zl_ev LZ[ebpZ (TABLE) y\ey_lky [Zah\hc kljmdlmjhc j_eypbhgghc fh^_eb
fgh`_kl\Z ihbf_gh\Zgguo klhe[ph\ beb Zljb[mlh\ Fgh`_kl\h agZq_gbc klhe[pZhij_^_e_ghkihfhsvxh]jZgbq_gbcp_ehklghklblh_klvih^^_j`b \Z_lkyh]jZgbq_ggZydhgp_ipby^hf_gZIhegh_bfylZ[ebpu\[Za_^Zgguo khklhblbabf_gbko_fu\^Zgghcj_ZebaZpbbkh\iZ^Zxs_fkbf_g_fihev ah\Zl_eykha^Z\r_]hlZ[ebpmbkh[kl\_gghbf_gblZ[ebpuLZ[ebpZfh`_l [ulv imklhc beb khklhylv ba h^ghc beb [he__ kljhd agZq_gbc Zljb[mlh\ KljhdbagZq_gbcZljb[mlh\lZ[ebpugZau\ZxlkylZd`_dhjl_`Zfb Ij_^klZ\e_gb_ (VIEW) — wlh ihbf_gh\ZggZy ^bgZfbq_kdb ih^^_j `b\Z_fZy k_j\_jhf \u[hjdZ ba h^ghc beb g_kdhevdbo lZ[ebp Hi_jZlhj SELECT, hij_^_eyxsbc \u[hjdm h]jZgbqb\Z_l \b^bfu_ ihevah\Zl_e_f ^Zggu_K_j\_j]ZjZglbjm_lZdlmZevghklvij_^klZ\e_gbylh_klvnhjfbjh \Zgb_ ij_^klZ\e_gby fZl_jbZebaZpby khhl\_lkl\mxs_]h aZijhkZ ijhba\h^blkydZ`^ucjZaijbbkihevah\Zgbbij_^klZ\e_gbyBkihevamyij_^klZ\ e_gbyZ^fbgbkljZlhj[_ahiZkghklbh]jZgbqb\Z_l^hklmigmxihevah\Zl_eyf qZklv[Zau^Zgguolhevdhl_fb^Zggufbdhlhju_j_Zevghg_h[oh^bfu^ey \uiheg_gby_]hjZ[hlu Ihevah\Zl_ey (USER) — h[t_dl h[eZ^Zxsbc \hafh`ghklvx kha^Z \Zlvbbkihevah\Zlv^jm]b_h[t_dluOracle,ZlZd`_aZijZrb\Zlv\uiheg_gb_ nmgdpbck_j\_jZDqbkemlZdbonmgdpbchlghkylkyhj]ZgbaZpbyk_kkbbba f_g_gb_khklhygbyk_j\_jZb[Zau^ZgguoaZijhkgZ\uiheg_gb_hi_jZlhjh\ SQLb^j >eymijhs_gbyj_r_gbyaZ^Zqb^_glbnbdZpbbbbf_gh\Zgby\[Z a_^Zgguo Oracleih^^_j`b\Z_lh[t_dluihke_^h\Zl_evghklvbkbghgbf Ihke_^h\Zl_evghklv (SEQUENCE) — wlh h[t_dl h[_ki_qb\Zxsbc ]_g_jZpbx mgbdZevguo ghf_jh\ \ mkeh\byo fgh]hihevah\Zl_evkdh]h Zkbg ojhggh]h ^hklmiZH[uqghwe_f_gluihke_^h\Zl_evghklbbkihevamxlky^ey \klZ\dbmgbdZevguob^_glbnbdZpbhgguoghf_jh\^eywe_f_glh\lZ[ebp[Z au^Zgguo Kbghgbf (SYNONYM) —wlhZevl_jgZlb\gh_bfy-ik_\^hgbfh[t_dlZ Oracle, dhlhjuc iha\hey_l ihevah\Zl_eyf [Zau ^Zgguo bf_lv ^hklmi d ^Zg ghfm h[t_dlm Kbghgbf fh`_l [ulv qZklguf b h[sbf H[sbc (public) kb ghgbf iha\hey_l \k_f ihevah\Zl_eyf [Zau ^Zgguo h[jZsZlvky d khhl\_lkl \mxs_fmh[t_dlmihZevl_jgZlb\ghfmbf_gb >eymijZ\e_gbywnn_dlb\ghklvx^hklmiZd^ZggufOracleih^^_j`b \Z_lh[t_dlubg^_dklZ[ebqgZyh[eZklvbdeZkl_j Bg^_dk (INDEX) — wlh h[t_dl [Zau ^Zgguo kha^Z\Z_fuc ^ey ih\u r_gbyijhba\h^bl_evghklb\u[hjdb^ZgguoBg^_dkkha^Z_lky^eyklhe[ph\ lZ[ebpubebij_^klZ\e_gby\ijhkljZgkl\_[Zau^Zgguobh[_ki_qb\Z_l[h e__[ukljuc^hklmid^Zgguf[Zau^ZgguoaZkq_lojZg_gbyijyfuokkuehd gZf_klhjZkiheh`_gbykljhdkh^_j`Zsbolj_[m_fu_^Zggu_ LZ[ebqgZyh[eZklv (TABLESPACE) —bf_gh\ZggZyqZklv[Zau^Zg guobkihevam_fZy^eyjZkij_^_e_gbyiZfylb^eylZ[ebpbbg^_dkh\ DeZkl_j (CLUSTER) —h[t_dlaZ^Zxsbckihkh[kh\f_klgh]hojZ
8
g_gby^Zgguog_kdhevdbolZ[ebpkh^_j`Z\rbobgnhjfZpbxh[uqghh[jZ [Zlu\Z_fmx kh\f_klgh DeZkl_jbaZpby klhe[ph\ lZ[ebp iha\hey_l mf_gv rblv\j_fy\uiheg_gby\u[hjdbKljhdblZ[ebpbf_xsb_h^bgZdh\h_agZ q_gb_ \ deZkl_jbah\Zgguo klhe[pZo ojZgylky \ [Za_ ^Zgguo ki_pbZevguf h[jZahf >eywnn_dlb\gh]hmijZ\e_gbyjZa]jZgbq_gb_f^hklmiZd^Zgguf Oracleih^^_j`b\Z_lh[t_dljhev Jhev (ROLE) — bf_gh\ZggZy kh\hdmighklv ijb\be_]bc dhlhju_ fh ]ml[ulvij_^hklZ\e_guihevah\Zl_eyfbeb^jm]bfjheyf Oracleih^^_j`b \Z_l g_kdhevdh klZg^Zjlguo beb ij_^hij_^_e_gguo jhe_c Ki_pbnbqgufb ^ey jZkij_^_e_gguo kbkl_f y\eyxlky h[t_dlu Oracle: kgbfhd b k\yav [Zau ^Zgguo Kgbfhd (SNAPSHOT) — ehdZevgZy dhiby lZ[ebpu m^Ze_gghc [Zau ^Zgguo dhlhjZy bkihevam_lky eb[h ^ey lbjZ`bjh\Zgby dhibjh\Zgby \k_c beb qZklb lZ[ebpu eb[h ^ey lbjZ`bjh\Zgby j_amevlZlZ aZijhkZ ^Zgguo ba g_kdhevdbo lZ[ebp Kgbfdb fh]ml [ulv fh^bnbpbjm_fufb beb ij_^gZagZq_ggufblhevdh^eyql_gbyKgbfdblhevdh^eyql_gby\hafh`ghi_jbh ^bq_kdb h[gh\eylv hljZ`Zy baf_g_gby hkgh\ghc lZ[ebpu Baf_g_gby k^_ eZggu_\fh^bnbpbjm_fhfkgbfd_jZkijhkljZgyxlkygZhkgh\gmxlZ[ebpm b^jm]b_dhibb K\yav[Zwu^Zgguo (DATABASE LINK) —wlhh[t_dl[Zau^Zgguo dhlhjuciha\hey_lh[jZlblvkydh[t_dlZfm^Ze_gghc[Zau^ZgguoBfyk\yab [Zau^Zgguofh`ghjZkkfZljb\ZlvdZdkkuedmgZiZjZf_ljuf_oZgbafZ^hk lmiZ d m^Ze_gghc [Za_ ^Zgguo bfy maeZ ijhlhdhe b l i Bkihevah\Zgb_ h^gh]hbf_gbmijhsZ_ljZ[hlmkh[t_dlZfbm^Ze_gghc[Zau^Zgguo >eyijh]jZffbjh\ZgbyZe]hjblfh\h[jZ[hldb^Zgguoj_ZebaZpbbf_ oZgbafh\ ih^^_j`db p_ehklghklb [Zau ^Zgguo Oracle bkihevam_l h[t_dlu ijhp_^mjZnmgdpbyiZd_lbljb]]_j Ijhp_^mjZ (PROCEDURE) —wlhihbf_gh\Zgguckljmdlmjbjh\Zg guc gZ[hj i_j_f_gguo b hi_jZlhjh\ SQL b PL/SQL, ij_^gZagZq_gguc ^ey j_r_gbydhgdj_lghcaZ^Zqb Nmgdpby (FUNCTION) — wlh ihbf_gh\Zgguc kljmdlmjbjh\Zgguc gZ[hji_j_f_gguobhi_jZlhjh\ SQLbPL/SQL,ij_^gZagZq_gguc^eyj_r_ gbydhgdj_lghcaZ^Zqbb\ha\jZsZxsbcagZq_gb_i_j_f_gghc IZd_l (PACKAGE) —wlhihbf_gh\Zgguckljmdlmjbjh\ZggucgZ[hj i_j_f_gguo ijhp_^mj b nmgdpbc k\yaZgguo _^bguf nmgdpbhgZevguf aZ fukehfGZijbf_jOracleihklZ\ey_liZd_l DBMS_OUTPUT.\dhlhjhfkh[ jZgu ijhp_^mju b nmgdpbb ij_^gZagZq_ggu_ ^ey hj]ZgbaZpbb \\h^Z\u\h^Z Ljb]]_j (TRIGGER) —wlhojZgbfZyijhp_^mjZdhlhjZyaZimkdZ_l kyZ\lhfZlbq_kdb\uihegy_lky lh]^Zdh]^Zijhbkoh^blk\yaZggh_kljb]]_ jhfkh[ulb_H[uqghkh[ulbyk\yaZguk\uiheg_gb_fhi_jZlhjh\ INSERT,
9
UPDATE beb DELETE\g_dhlhjhclZ[ebp_
2. Lbiu^ZgguoORACLE Kljhdh\u_lbiu
Lbi CHARACTER bkihevam_lky ^ey ojZg_gby kljhd nbdkbjh\Zgghc ^ebgu KbglZdkbkCHARACTER>^ebgZ @CHAR>^ebgZ @ FZdkbfZevgh_agZq_gb_iZjZf_ljZ^ebgZ–kbf\heh\ LbiVARCHAR bkihevam_lky^eyojZg_gbykljhdi_j_f_gghc^ebgu Ke_^mxsb_ij_^eh`_gbywd\b\Ze_glgu 9$5&+$5>^ebgZ @ &+$5 9$5<,1*>^ebgZ @ &+$5$&7(5 9$5<,1*>^ebgZ @ ?keb ^ebgZ kljhdb g_ mdZaZgZ y\gh hgZ iheZ]Z_lky jZ\ghc \h \k_o kemqZyo FZdkbfZevgh_ agZq_gb_ iZjZf_ljZ ^ebgZ – kbf\heh\ ^ey ihke_^gbolj_okemqZ_\ Ijbf_ju Str1 CHAR(15) Str2 CHARACTER VarSts1 VARCHAR (15) VarStr2 CHARACTER VARYING (10) ?klvlbioZjZdl_jguclhevdh^eyORACLE VARCHAR>^ebgZ @ Kihfhsvxwlh]hlbiZj_a_j\bjm_lkyg_h[oh^bfh_ijhkljZgkl\h >ey ojZg_gby [hevrbo kljhd i_j_f_gghc ^ebgu bkihevam_lky lbi LONG>^ebgZ @ _keb iZjZf_lj ^ebgZ g_ mdZaZg lh ij_^iheZ]Z_lky qlh m kljhdb^ebgZf_]Z[ZclZfZdkbfZevgZy^ebgZ]b]Z[ZclZ
Qbkeh\u_lbiu Lbi INTEGERbkihevam_lky^eyij_^klZ\e_gbyqbk_ehl –231 ^h 231 . KbglZdkbk: INTEGER, INT. Ijbf_j varint INTEGER varint2 INT Lbi NUMBER>Lhevdh^ey Oracle]bkihevam_lky^ey ij_^klZ\e_gby qbk_ekaZ^ZgghclhqghklvxKbglZdkbk NUMBER [lhqghklv [,fZk rlZ[@ @ ?keb agZq_gb_ iZjZf_ljZ lhqghklv g_ mdZaZgh y\gh hgh iheZ]Z_lky jZ\guf 38.AgZq_gb_iZjZf_ljZfZkrlZ[ihmfheqZgbxij_^iheZ]Z_lkyjZ\ guf0AgZq_gb_iZjZf_ljZlhqghklvfh`_lbaf_gylvkyhl 1^h 38;agZq_gb_ 10
iZjZf_ljZfZkrlZ[fh`_lbaf_gylvkyhl -84^h 128.Bkihevah\Zgb_hljbpZ l_evguo agZq_gbc fZkrlZ[Z hagZqZ_l k^\b] ^_kylbqghc lhqdb \ klhjhgm klZjrbo jZajy^h\ GZijbf_j hij_^_e_gb_ NUMBER ( 7 , -3 ) hagZqZ_l hd jm]e_gb_^hlukyq DECIMAL b NUMERIC iheghklvx wd\b\Ze_glgu lbim Tunu NUMBER. KbglZdkbk DECIMAL [lhqghklv [, fZkrlZ[@ @, DEC [lhqghklv [, fZkrlZ[@ NUMERIC [lhqghklv [,fZkrlZ[@ @ Ijbf_juYDUFRXQWHU180%(5 Vardec1 DEC vardec2 DEC (7) vardec3 DECIMAL (7,3) varnum NUMERIC
;blh\u_ kljhdb Lbi RAW >Lhevdh ^ey Oracle] bkihevam_lky ^ey ojZg_gby [blh\uo kljhdi_j_f_gghc^ebguHlebqb_lbiZ RAW hllbih\ CHAR, VARCHAR2 khklhbl \ lhf qlh ^ey lbih\ kbf\hevguo kljhd Oracle lhqg__ SQL*Net) ijhba\h^blZ\lhfZlbq_kdh_ij_h[jZah\Zgb_^Zgguoijbboi_j_^Zq_f_`^m deb_glhfbk_j\_jhf KbglZdkbk RAW [^ebgZ ].IZjZf_lj^ebgZbaf_jy_lky\[ZclZoFZd kbfZevgh_agZq_gb_iZjZf_ljZ^ebgZ — 255[Zcl Lbi LONG RAW >Lhevdh ^ey Oracle] bkihevam_lky ^ey ojZg_gby [hevrbo[blh\uokljhdi_j_f_gghc^ebgu KbglZdkbk LONG RAW[^ebgZ ].IZjZf_lj^ebgZbaf_jy_lky\[ZclZo ?keb ^ebgZ kljhdb g_ mdZaZgZ y\gh hgZ iheZ]Z_lky jZ\ghc 2 f_]Z[ZclZf FZdkbfZevgh_agZq_gb_iZjZf_ljZ^ebgZ — 2]b]Z[ZclZkbf\heh\>eyi_j_ f_gguolbiZ LONG RAWg_\hafh`ghihkljh_gb_bg^_dkZ Ijbf_ju Bit1 RAW(15) verylongl LONG RAW( 100000)
2.4. Lbiu^ZlZb\j_fy
Lbi DATE>Lhevdh^ey Oracle]bkihevam_lky^eyojZg_gby^Zlub\j_ f_gbIh^^_j`b\Zxlky^Zluk 1yg\Zjy4712]^hgw^h 31^_dZ[jy 4712] gw>eygZqZevgh]hijbk\Zb\Zgby^Zluh[uqghbkihevam_lkynmgdpby LHBDATE kbf\hevgZyBkljhdZB^Zlu nhjfZlB^Zlu Ijb hij_^_e_gbb ^Zlu [_a mlhqg_gby \j_f_gb ih mfheqZgbx ijbgbfZ_lky \j_fy ihemghqb Nmgdpby SYSDATE ijbk\Zb\Z_l i_j_f_gghc l_dms__ agZq_gb_ ^Zlu b \j_ f_gb KbglZdkbk: DATE. Ijbf_j birthday DATE GZebqb_ ki_pbZevgh]h lbiZ ^ey ojZg_gby ^Zlu b \j_f_gb iha\hey_l ih^^_j`b\Zlv ki_pbZevgmx Zjbnf_lbdm ^Zl b \j_f_g >h[Z\e_gb_ d i_j_ 11
f_gghc lbiZ DATEp_eh]hqbkeZhagZqZ_lm\_ebq_gb_^ZlugZkhhl\_lkl\m ]hs__ qbkeh ^g_c Z \uqblZgb_ \uihegy_lky dZd hij_^_e_gb_ [he__ jZgg_c ^ZluJZkkfhljbfg_kdhevdhijbf_jh\ SQL > select sysdate from dual; SYSDATE 15-NOV-98 SQL> select sysdate+20 "sysd+20" from dual; sysd+20 05-DEC-98 SQL> select sysdate-20 "sysd-20" from dual; sysd-20 26-OCT-98
3. L:;EBPU
3.1. Kha^Zgb_lZebp LZ[ebpZ y\ey_lky [Zah\hc kljmdlmjhc j_eypbhgghc fh^_eb Ihegh_ bfylZ[ebpu\[Za_^Zgguokhklhblbabf_gbko_fudZdijZ\behkh\iZ^Zx s_fkbf_g_fihevah\Zl_eybbf_gblZ[ebpu Hi_jZlhjhij_^_e_gbylZ[ebpbf__lke_^mxsbckbglZdkbk CREATE TABLE >bfyBko_fu@bfylZ[ebpu (^h]jZgbq_gb_Bp_ehklghklbBlZ[ebpu IbfyBklhe[pZ lbiB^ZgguoBklhe[pZ ['()$8/7\ujZ`_gb_@>h]jZgbq_gb_Bp_ehklghklbBklhe[pZ«@`« [{ CLUSTERbfyBdeZkl_jZbfyBklhe[pZ>@ I {PCTFREE p_eh_ I PCTUSED p_eh_ I INITRANS p_eh_ I MAXTRANS p_eh_ I TABLESPACE bfy_lZ[ebqghc_h[eZklb I 6725$*(jZaf_jiZfylb, RECOVERABLE I UNRECOVERABLE}} ...] [PARALLEL\hafh`ghklvBiZjZee_evghcBh[jZ[hldb ] {{ENABLEijh\_jy_fu_Bh]jZgbq_gbyBp_ehklghklb } ...] [AS aZijhk] [GACHE I NOCACHE] Dexq_\h_keh\h DEFAULTmdZau\Z_lgZlhqlhijb\\h^_^Zgguokh hl\_lkl\mxs_fmklhe[pm[m^_lijbk\h_ghagZq_gb_hij_^_e_ggh_i_j_f_g ghc\ujZ`_gb__keb\hi_jZlhj_INSERTg_mdZaZghy\gh^jm]h_agZq_gb_ klhe[pZ Lbi ^Zgguo \ujZ`_gb_ ^he`_g khhl\_lkl\h\Zlv lbim ^Zgguo
12
klhe[pZb\ujZ`_gb_g_^he`ghkh^_j`ZlvkkuehdgZ^jm]b_\ujZ`_gby Dexq_\h_ keh\h PCTFREE, PCTUSED, INITRANS, MAXTRANS, TABLESPACE, STORAGE, RECOVERABLE, UNRECORECOVERABLE oZ jZdl_jbamxlijhkljZgkl\hjZkij_^_ey_ijbjZ[hl_klZ[ebp_c Dexq_\h_keh\h PCTFREEhij_^_ey_lijhp_glijhkljZgkl\Z[ehdZdh lhjucj_a_j\bjm_lky^eyfh^bnbdZpbblZ[ebpu>himklbfu_agZq_gbyhl ^h 99. AgZq_gb_ ih mfheqZgbx 10, lh _klv ijb aZiheg_gbb dZ`^h]h [ehdZ ijhkljZgkl\ZhklZ_lkyg_bkihevah\Zgguf Dexq_\h_keh\h PCTUSEDhij_^_ey_lfbgbfZevgucijhp_glbkihev ah\ZgbyijhkljZgkl\Z[ehdZijbdhlhjhf\g_]h\\h^ylky^Zggu_ihmfhe qZgbx 40, lh _klv _keb \[ehd_aZgylhf_g__%ijhkljZgkl\Z\g_]h\\h ^ylky^Zggu_ijb\uiheg_gbbhi_jZpbb\klZ\db JZkkfhljbf[Zam^Zgguoke_^mxs_ckljmdlmju LZ[ebpZSTUDENTKlm^_gl BIRTHSTUSURNAME NAME STIPEND KURS CITY DAY DENT_ID
UNIV_ID
STUDENT_ID –b^_glbnbdZlhjklm^_glZ SURNAME –nZfbebyklm^_glZ NAME –bfyklm^_glZ STIPEND –klbi_g^bydhlhjmxihemqZ_lklm^_gl KURS –dmjkgZdhlhjhfmqblkyklm^_gl CITY –]hjh^\dhlhjhf`b\_lklm^_gl BIRTHDAY –^ZlZjh`^_gbyklm^_glZ UNIV_ID –b^_glbnbdZlhjmgb\_jkbl_lZ\dhlhjhfmqblkyklm^_gl LZ[ebpZLECTUREIj_ih^Z\Zl_ev LECTURE _ID SURNAME NAME CITY
UNIV_ID
LECTURE_ID –b^_glbnbdZlhjij_ih^Z\Zl_ey SURNAME –nZfbebyij_ih^Z\Zl_ey NAME –bfyij_ih^Z\Zl_ey CITY –]hjh^\dhlhjhf`b\_lij_ih^Z\Zl_ev UNIV_ID –b^_glbnbdZlhjmgb\_jkbl_lZ\dhlhjhfjZ[hlZ_lij_ih^Z\Zl_ev
13
LZ[ebpZSUBJECTIj_^f_lh[mq_gby SUBJ_ID SUBJ_NAME HOUR SEMESTR SUBJ_ID –b^_glbnbdZlhjij_^f_lZh[mq_gby SUBJ_NAME –gZbf_gh\Zgb_ij_^f_lZh[mq_gby HOUR –dhebq_kl\hqZkh\hl\h^bfuogZbamq_gb_ij_^f_lZ SEMESTR –k_f_klj\dhlhjhfbamqZ_lky^Zggucij_^f_l LZ[ebpZUNIVERSITY Mgb\_jkbl_lu UNIV_ID UNIV_NAME RATING
CITY
UNIV_ID –b^_glbnbdZlhjmgb\_jkbl_lZ UNIV_NAME –nZfbebyklm^_glZ RATING –j_clbg]mgb\_jkbl_lZ CITY –]hjh^\dhlhjhfjZkiheh`_gmgb\_jkbl_l LZ[ebpZEXAM_MARKSWdaZf_gZpbhggu_hp_gdb EXAM_ID STUDENT_ID SUBJ_ID MARK EXAM_DATE EXAM_ID –b^_glbnbdZlhjwdaZf_gZ STUDENT_ID –b^_glbnbdZlhjklm^_glZ SUBJ_ID –b^_glbnbdZlhjij_^f_lZh[mq_gby MARK –wdaZf_gZpbhggZyhp_gdZ EXAM_DATE –^ZlZwdaZf_gZ LZ[ebpZSUBJ_LECTMq_[gu_^bkpbiebguij_ih^Z\Zl_e_c LECTURE _ID SUBJ_ID LECTURE _ID –b^_glbnbdZlhjij_ih^Z\Zl_ey SUBJ_ID –b^_glbnbdZlhjij_^f_lZh[mq_gby
Yaud PL/SQL Yaud PL/SQL y\ey_lky khklZ\ghc qZklvx \h fgh]bo ijh^mdlZo Oracle. K_j\_j Oracle\dexqZ_lih^^_j`dmyaudZPL/SQL,ij_^hklZ\eyyihevah\Zl_ ex\hafh`ghklvkha^Z\Zlvbbkihevah\ZlvgZk_j\_j_ijhp_^mjubljb]]_ju [Zau ^Zgguo \uihegyxsb_ aZ^Zqb dhgdj_lgh]h ijbeh`_gby Ijh]jZffu kha^Zggu_ gZ yaud_ PL/SQL, fh]ml jZ[hlZlv kh\f_klgh \ jZaebqguo qZklyo ijbdeZ^ghc kbkl_fu ihkljh_gghc gZ kj_^kl\ZoOracle.GZijbf_j\ijbeh `_gbb bkihevamxs_f jZ[hlm k nhjfZfb ljb]]_j fh`_l \uau\Zlv ^ey \u iheg_gbyg_dhlhjh]h^_ckl\byojZgbfmxijhp_^mjm
14
set serveroutput on; SQL> set echo on; SQL> DECLARE --\oh^ ------- Arg -gZqZevgh_agZq_gb_ --\uoh^ -------Header1, Header2 -dhgklZglu^ey\uoh^Z 2 Header1 CONSTANT VARCHAR2(20) := ' Wdkihg_glZ ^\mo jZ\gZ '; 15
3 Header2 CONSTANT VARCHAR2(20) := Wdkihg_glZ lj_o jZ\gZ‘; 4 Arg NUMBER := 2; --a^_kvaZ^Z_lkygZqZevgh_agZq_gb_Zj]mf_glZ 5 -- Bkihegbl_evguc [ehd 6 BEGIN 7 DBMS_OUTPUT.PUT_LINE(Headerl II Exp (Arg) ) ; 8 Arg := Arg+l; 9 DBMS_OUTPUT.PUT_LINE (Header2 II Exp (Arg) ) ; 10 END; 11 /
MIJ:<E?GB?
Hi_jZlhju[hevrbgkl\Zyaudh\ijh]jZffbjh\Zgby\lhfqbke_byaudZ PL/SQL, \uihegyxlky ihke_^h\Zl_evgh LZdZy ko_fZ gZau\Z_lky ihlhdhf dhfZg^ < PL/SQL ij_^mkfhlj_gh g_kdhevdh hi_jZlhjh\ k ihfhsvx dhlh juo fh`gh mijZ\eylv \uiheg_gb_f ijh]jZffu JZkkfhljbf khhl\_lkl\mxsb_ijh]jZffgu_dhgkljmdpbb 4.1.1. Hi_jZlhj\_l\e_gby Hi_jZlhj IF. . .THEN. . .ELSEiha\hey_lijh\_jblvmkeh\b_b\aZ\b kbfhklbhlj_amevlZlh\ijh\_jdb (TRUEbebFALSE),\uihegblvjZaebqgu_ ]jmiiu hi_jZlhjh\ :evl_jgZlb\gZy ihke_^h\Zl_evghklv hi_jZlhjh\ hij_ ^_ey_lky dexq_\uf keh\hf ELSE. =jZgbpu ^_ckl\by hi_jZlhjZ IF hij_^_eyxlky aZdju\Zxs_c hi_jZlhjghc kdh[dhc END IF. >ey jZkrbj_gby kljmdlmju \_l\e_gby ^hihegbl_evgh ij_^mkfhlj_gu hi_jZlhjgu_ kdh[db ELSIF,aZ^Zxsb_kljmdlmju\_l\e_gby[he__]em[hdh]hmjh\gy Oraclebkihevam_lke_^mxsbckbglZdkbkdhgkljmdpbb\_l\e_gby\ PL/SQL: IF mkeh\b_B THEN hi_jZlhjuB; —\_l\v 1 ELSIFmkeh\b_B THEN hi_jZlhju; —\_l\v ELSIF ELSE hi_jZlhjBn -hi_jZlhjuZevl_jgZlb\uEND IF; H[jZlbl_\gbfZgb_qlhhi_jZlhj^hihegbl_evgh]h\_l\e_gbydh^bjm _lky dexq_\uf keh\hf ELSIF Z g_ ELSEIF, dZd bgh]^Z ij_^iheZ]Zxl g_ hq_gv\gbfZl_evgu_ihevah\Zl_eb JZkkfhljbf ijbf_j beexkljbjmxsbc f_oZgbaf \_l\e_gby \ ijh ]jZffZogZ PL/SQL.Ijh]jZffZ\u\h^blkhh[s_gb_hijbgZ^e_`ghklbx g_ dhlhjhfm bgl_j\Zem >ey \\h^Z ^Zgguo bkihevam_lky klZg^Zjlgh_ kh]eZr_ gb_ PL/SQL:i_j_f_ggZybfydhlhjhcij_^\Zjy_lkyagZdhf "&",\\h^blkyk l_jfbgZeZihevah\Zl_ey
16
IJBF?J SQL> DECLARE --\oh^ - x-i_j_f_ggZygZ\oh^_ \uoh^ - Text1,Text2,Text3-kljhdb^ey\u\h^Z 2 x NUMBER; --i_j_f_ggZy 3 Textl VARCHAR2(30) := I_j_f_ggZy>= 10 '; 4 Text2 VARCHAR2(30) := I_j_f_ggZy\^bZihahg_hl^h '; 5 Text3 VARCHAR2(30) := I_j_f_ggZy<= 0 '; 6 --Bkihegbl_evguc[ehd 7 BEGIN 8 x := &lnput_Data; 9 DBMS_OUTPUT . PUT_LINE ( ‘ ‘); 10 IF (x > 10) 11 THEN DBMS_OUTPUT.PUT_LINE(Textl); 12 ELSIF (x < 0) 13 THEN DBMS_OUTPUT. PUT_LINE ( Text2 ) ; 14 END IF; 15 END; 16 / HI?J:LHJPBDE: Hj]ZgbaZpbypbdeZhnhjfey_lky\ijh]jZff_gZPL/SQLhi_jZlhjhf LOOP. DECLARE 2 Arg NUMBER; --I_j_f_ggZy^ey\uqbke_gbynZdlhjbZeZ 3 I NUMBER; --I_j_f_ggZy-kq_lqbd 4 Limit NUMBER := 1000000000; --=jZgbqgh_agZq_gb_ 5 Textl VARCHAR2(80) :== NZdlhjbZeqbkeZ\i_j\u_ij_\urZxsbc 1 000 000 000 '; 6 --Bkihegbl_evguc[ehd 7 BEGIN 8 I :=l; 9 Arg := 1; 10 LOOP
17
11 EXIT WHEN ARG > Limit; 12 I :=I+1; 13 Arg := Arg* I; 14 END LOOP; 15 DBMS_OUTPUT. PUT_LINE ( Textl ) ; 16 DBMS_OUTPUT. PUT_LINE ( TO_CHAR ( Arg ) ) ; 17 DBMS_OUTPUT. PUT_LINE (‘Bkdhfh_ qbkeh = ‘ II TO_CHAR(I) ); 18 END; 19 / ?s_h^gbfjZkijhkljZg_gguf\ZjbZglhfhj]ZgbaZpbbpbdeZy\ey_lky pbde mijZ\ey_fuc dexq_\uf keh\hf WHILE. MijZ\e_gb_ lbiZ WHILE h[_ki_qb\Z_l \uiheg_gb_ pbdeZ ^h l_o ihj, ihdZ mkeh\b_ hij_^_e_ggh_ dexq_\ufkeh\hfWHILE,y\ey_lkybklbgguf (TRUE).Fh^bnbpbjm_fij_ ^u^msbcijbf_jbaf_gb\dhgklZglmbaZ^Z\mkeh\b_\uoh^ZbapbdeZdex q_\ufkeh\hf WHILE. IJBF?J 4.1.2.2. SQL> DECLARE 2 Arg NUMBER; --I_j_f_ggZy^ey\uqbke_gbynZdlhjbZeZ 3 I NUMBER; --I_j_f_ggZy-kq_lqbd 4 Limit NUMBER := 1000000000000; --=jZgbqgh_agZq_gb_ 5 Textl VARCHAR2(80) := NZdlhjbZeqbkeZ\i_j\u_ij_\urZxsbc 1 000 000 000 000 '; 6 --Bkihegbl_evguc[ehd 7 BEGIN 8 I:=l; 9 Arg := 1; 10 WHILE Arg < 1000000000000 LOOP 11 I:=I+1; 12 Arg := Arg* I; 13 END LOOP; 14 DBMS_OUTPUT.PUT_LINE(Textl); 15 DBMS_OUTPUT. PUT_LINE ( TO_CHAR ( Arg ) ) ; 16 DBMS_OUTPUT .PUT_LINE ('Bkdhfh_ qbkeh = II TO_CHAR(I) ); 17 END; 18 / NZdlhjbZeqbkeZ,\i_j\u_ij_\urZxsbc1 000 000 000 000 10461394944000 Bkdhfh_ qbkeh = 15 PL/SQL procedure successfully completed. PbdemijZ\ey_fuchi_jZlhjhf FOR,bkihevam_lky\lhfkemqZ_dh]^Z lhqghba\_klghkdhevdhjZagm`gh\uihegylvbl_jZpbxpbdeZJZkkfhljbf ijbf_j jZkq_lZ nZdlhjbZeZ aZ^Zggh]h qbkeZ H[jZlbl_ \gbfZgb_ qlh i_j_ f_ggmxpbdeZhibku\Zlv\[ehd_ DECLAREg_gm`gh
18
IJBF?J 4.1.2.3. SQL> DECLARE 2 Arg NUMBER := 1; --I_j_f_ggZy^ey\uqbke_gbynZdlhjbZeZ 3 Limit NUMBER := 20; --=jZgbqgh_agZq_gb_ 4 Textl VARCHAR2(30) := NZdlhjbZeqbkeZ20 = '; 5 -- Bkihegbl_evguc [ehd 6 BEGIN 7 FOR I IN 1.. Limit LOOP 8 Arg := Arg* I; 9 END LOOP; 10 DBMS_OUTPUT.PUT_LINE(Textl I I TO_CHAR ( Arg ) ) ; 11 END; 12 / 4Hi_jZlhj GOTO Hi_jZlhj i_j_oh^Z GOTO iha\hey_l hkms_kl\blv i_j_oh^ ih f_ld_ ijbkmlkl\mxs_c\l_e_ijh]jZffuKihfhsvxmgbdZevgh]hb^_glbnbdZlh jZ aZdexq_ggh]h \ ^\hcgu_ m]eh\u_kdh[dbfh`ghihf_lblvex[mxqZklv ijh]jZffu PL/SQL^eyhj]ZgbaZpbb[_amkeh\gh]hi_j_oh^Zihf_ld_
Dmjkhju
Dexq_\uf ihgylb_f yaudZ PL/SQL y\ey_lky dmjkhj Dmjkhj — wlh ih bf_gh\Zgguc aZijhk kh^_j`Zsbc g_dhlhjh_ nbdkbjh\Zggh_ qbkeh kljhd \ \u[hjd_ QZs_ \k_]h dmjkhj kh^_j`bl ^Zggu_ h^ghc kljhdb \u[bjZ_fhc lZ[ebpu Ih kms_kl\m dmjkhj y\ey_lky hdghf q_j_a dhlhjh_ ihevah\Zl_ev ihemqZ_l ^hklmi d bgnhjfZpbb [Zau ^Zgguo Dmjkhju \ qZklghklb fh]ml bkihevah\Zlvky ^ey ijbk\Zb\Zgby dhgdj_lguo agZq_gbc i_j_f_gguf ijh ]jZffu JZkkfhljbfijbf_j^hklmiZdbgnhjfZpbbojZgbfhc\[Za_^Zgguok bkihevah\Zgb_fdmjkhjh\Imklv\[Za_^ZgguoojZgblkylZ[ebpZ LECTURE, CREATE TABLE LECTURE knhjfbjh\ZggZy ij_^eh`_gbyfb (LECTURE_ID NUMBER, SURNAME VARCHAR2(30), NAME VARCHAR2(10), CITY VARCHAR2(30), UNIV_ID NUMBER); INSERT INTO LECTURE VALUES (1, 'B\Zgh\', 'B\Zg
OPEN Curl; set serveroutput on; SQL> set echo on; SQL> set termout on; SQL> DECLARE 2 Argl NUMBER; -- I_j_f_ggZy ^ey i_j\h]h Zj]mf_glZ 3 Arg2 VARCHAR2(30); --I_j_f_ggZy^ey \lhjh]hZj]mf_glZ 4 Arg3 VARCHAR2(10); --I_j_f_ggZy^ey lj_lv_]hZj]mf_glZ 5 Arg4 VARCHAR2(30); --I_j_f_ggZy^ey q_l\_jlh]hZj]mf_glZ 6 Arg5 NUMBER; --I_j_f_ggZy^ey iylh]hZj]mf_glZ 7 Cursor Curl IS SELECT * FROM LECTURE; --Hij_^_e_gb_ dmjkhjZ 8 BEGIN 9 Open Curl; --Dmjkhj^he`_g[ulvhldjul 10 FOR I IN 1 ..3 LOOP 11 FETCH Curl INTO Argl,Arg2; 12 DBMS_OUTPUT.PUT_LINE(TO_CHAR(Argl) 13 END LOOP; 14 END; 15 / <^Zgghcijh]jZff_g_m^ZqghmijZ\e_gb_kq_lqbdhfihkdhevdmpbde gZkljh_ggZ ihemq_gb_dhgdj_lgh]hqbkeZkljhddhlhjuofh`_lbg_[ulv\ lZ[ebp_ < PL/SQL ^ey dmjkhjh\ ij_^mkfhlj_gu ki_pbZevgu_ f_lh^u %NOTFOUND b %FOUND,ijbgbfZxsb_ijhlb\hiheh`gu_[me_\kdb_agZ q_gby F_lh^ %oNOTFOUND \ha\jZsZ_l agZq_gb_ TRUE, _keb \u[hjdZ \ dmjkhjimklZylh_klvg_kh^_j`blkljhdbIhke_hldjulbydmjkhjZgh^h i_j\hc dhfZg^u FETCH, f_lh^u FOUND, %NOTFOUND ijbgbfZxl g_ hij_^_e_ggh_ agZq_gb_ (unknown) G_agZgb_ wlh]h nZdlZ fh`_l ijb\_klb d ^hklZlhqghjZkijhkljZg_gghchrb[d_Ijbhj]ZgbaZpbbpbdeZkbkihevah\Z gb_f hi_jZlhjZ WHILE b \uiheg_gb_f ijh\_jdb gZ bklbgghklv %FOUND gZ \oh^_ pbde g_ [m^_l \uiheg_g gb jZam g_kfhljy gZ gZebqb_ ^Zgguo \ lZ[ebp_ F_lh^ %ROWCOUNT \ha\jZrZ_l qbkeh kljhd \u[jZgguo ihke_ hldjulbydmjkhjZ 20
Ihe_agh_ k\hckl\h k\yaZgh k ih^^_j`dhc iSH^RiSH^HeHggRUR f_lh^Z %TYPE. Lbi i_j_f_gghc fh`_l [ulv hij_^_e_g dZd kh\iZ^Zxsbc k lbihf Zljb[mlZ g_dhlhjhc lZ[ebpu Ijb wlhf ihevah\Zl_ex g_ lj_[m_lky lhqgh]h agZgby lbiZ ^Zgguo Zljb[mlh\ aZibkb [he__ lh]h ijb hij_^_e_gguo baf_ g_gbyo\lbiZo^ZgguolZ[ebpuijh]jZffZhklZ_lkyjZ[hlhkihkh[ghc < PL/SQL ih^^_j`b\Z_l lbi ^Zgguo RECORD, dhlhjuc iha\hey_l kdhgkljmbjh\Zlv h[t_dl khhl\_lkl\mxsbc kljhd_ lZ[ebpu H[jZs_gb_ d we_f_glZf h[t_dlZ lbiZ RECORD hkms_kl\ey_lky k ihfhsvx ghlZpbb bfy_h[v_dlZbfy_we_f_glZ K mq_lhf ^hihegbl_evguo h[t_dlh\ b f_lh^h\ PL/SQL jZkkfhljbf gh\uc \ZjbZgl ijh]jZffu \u[hjdb kljhd lZ[ebpu LECTURE c bkihevah\Zgb_f dmjkhjh\ H[jZlbl_ \gbfZgb_ gZ ih\lhjguc \u\h^ ihke_^g_c kljhdb IhiulZcl_kv bkijZ\blv hj]ZgbaZpbx pbdeZ ^ey mkljZg_gbyih\lhjgh]h\u\h^Z IJBF?J 4.2.2. SQL> set serveroutput on; SQL> set echo on; SQL> set tennout on; SQL> DECLARE 2 TYPE Tabl_rec_type IS RECORD -- Hij_^_e_gb_ gh\h]h lbiZ ^Zgguo 3 (Argl LECTURE. LECTURE _ID%TYPE, -- I_j_f_ggZy lbiZ Zljb[mlZ LECTURE_ID lZ[ebpu LECTURE 4 Arg2 LECTURE .SURNAME%TYPE, -- I_j_f_ggZy lbiZ Zljb[mlZ SURNAME lZ[ebpu LECTURE 5 Arg3 LECTURE.NAME%TYPE , -- I_j_f_ggZy lbiZ Zljb[mlZ NAME lZ[ebpu LECTURE 6 Arg4 LECTURE.CITY%TYPE , --I_j_f_ggZy lbiZ Zljb[mlZ CITY lZ[ebpu LECTURE 7 Arg5 LECTURE.UNIV_ID%TYPE); -- I_j_f_ggZy lbiZ Zljb[mlZ UNIV_ID lZ[ebpu LECTURE 8 TZb1B]_k Tabl_rec_type; --Hij_^_e_gb_h[t_dlZkdhgkljmbjh\Zggh]h lbiZ 9 Cursor Curl IS SELECT * FROM LECTURE; --Hij_^_e_gb_ dmjkhjZ 10 BEGIN 11 Open Curl; --Dmjkhj^he`_g[ulvhldjul 12 FETCH Curl INTO Tabl_rec; 13 LOOP 14 EXIT WHEN (Curl%NOTFOUND); 15 DBMS_OUTPUT.PUT_LINE(Curl%ROWCOUNT II' 'IITabl_rec. Arg2 II' 'IITabl_rec.Arg3 II' 'IITabl_rec.Arg4); 16 FETCH Curl INTO Tabl_rec; 17 END LOOP; 21
18 END; 19 / Hi_jZlhj hij_^_e_gby dmjkhjZ fh`_l kh^_j`Zlv iZjZf_ljbq_kdbc aZ ijhkAgZq_gbyiZjZf_ljZaZ^ZxlkyijbhldjulbbdmjkhjZ JZkkfhljbfijbf_j\u[hjdb^ZgguokiZjZf_ljbq_kdbfaZijhkhfb hj ]ZgbaZpb_cpbdeZbkdexqZxs_cih\lhjguc\u\h^ihke_^g_ckljhdb IJBF?J 4.2.3. SQL> DECLARE 2 TYPE Tabl_rec_type IS RECORD -- Hij_^_e_gb_ gh\h]h lbiZ ^Zgguo 3 (Argl LECTURE. LECTURE _ID%TYPE, -- I_j_f_ggZy lbiZ Zljb[mlZ LECTURE_ID lZ[ebpu LECTURE 4 Arg2 LECTURE .SURNAME%TYPE, -- I_j_f_ggZy lbiZ Zljb[mlZ SURNAME lZ[ebpu LECTUR 5 Arg3 LECTURE.NAME%TYPE , -- I_j_f_ggZy lbiZ Zljb[mlZ NAME lZ[ebpu LECTURE 6 Arg4 LECTURE.CITY%TYPE , --I_j_f_ggZy lbiZ Zljb[mlZ CITY lZ[ebpu LECTURE 7 Arg5 LECTURE.UNIV_ID%TYPE); -- I_j_f_ggZy lbiZ Zljb[mlZ UNIV_ID lZ[ebpu LECTURE 8 TZb1B]_k Tabl_rec_type; --Hij_^_e_gb_h[t_dlZkdhgkljmbjh\Zggh]h lbiZ 9 Cursor Cur2(I NUMBER) IS SELECT * FROM LECTURE WHERE CITY ¶
4.3. H[jZ[hldZbkdexqbl_evguokblmZpbc
;hevrbgkl\h jZa\bluo yaudh\ ijh]jZffbjh\Zgby h[eZ^Zxl \kljh_g gufbf_oZgbafZfbh[jZ[hldbbkdexqbl_evguokblmZpbcKhhl\_lkl\mxsb_ yaudh\u_kj_^kl\Zij_^mkfhlj_gub\ PL/SQL.Ijb\hagbdgh\_gbb\kbkl_ f_ ij_^hij_^_e_gghc beb hibkZgghc ihevah\Zl_e_f kblmZpbb ijhbkoh^bl Z\lhfZlbq_kdZyi_j_^ZqZmijZ\e_gby\gm`gucnjZ]f_gl[ehdZ EXCEPTION ijh]jZffu gZ PL/SQL, ]^_ b ijhbkoh^bl ij_^mkfhlj_ggZy h[jZ[hldZ \ha gbdr_cbkdexqbl_evghckblmZpbb 22
G_dhlhju_ ij_^hij_^_e_ggu_ bkdexqbl_evgu_ kblmZpbb PL/SQL ij_^klZ\e_gu \ lZ[ebp_. Iheguc i_j_q_gv bkdexqbl_evguo kblmZpbc fh `_l[ulvgZc^_g\jmdh\h^kl\_ihyaudm PL/SQL. Kbf\hebq_kdh_bfyij_^hij_^_e_gghc HibkZgb_ ij_^hij_^_e_gghcbk bkdexqbl_evghckblmZpbb dexqbl_evghckblmZpbb LOGIN_DENIED
G_mki_rgh_ ih^dexq_gb_ d k_j\_jm gZijbf_j \\_^_g hrb[hqguc iZ jhev
NOT_LOGGED_ON
IhiuldZ \uihegblv ^_ckl\b_ [_a ih^dexq_gbyd k_j\_jm Oracle
INVALID_CURSOR
KkuedZgZg_^himklbfucdmjkhjbeb g_^himklbfZyhi_jZpbykdmjkhjhf
1
2
NO_DATA_FOUND
G_ gZc^_gu ^Zggu_ khhl\_lkl\mx sb_hi_jZlhjm SELECT INTO
DUP_VAL_ON_INDEX
IhiuldZ\klZ\blvagZq_gb_-^m[ebdZl \ klhe[_p k h]jZgbq_gb_f gZ mgb dZevghklvagZq_gby
TOO_MANY_ROWS
Hi_jZlhj SELECT INTO \ha\jZsZ_l [he__h^ghckljhdb\i_j_f_ggmx
VALUE_ERROR
:jbnf_lbq_kdZy hrb[dZ hrb[dZ ij_h[jZah\Zgbybebmk_q_gbb
JZkkfhljbf ijbf_jijh]jZffukh[jZ[hldhcbkdexqbl_evguokblmZ pbc<l_dkl_ijh]jZffuijhims_ghi_jZlhjhldjulbydmjkhjZihwlhfmijb h[jZs_gbb d f_lh^m % FOUND g_hldjulh]h dmjkhjZ \hagbdg_l bkdexqb l_evgZy kblmZpby INVALID_CURSOR. IJBF?J 4.3.1. SQL> DECLARE 2 Argl LECTURE. LECTURE _ID%TYPE; 3 Arg2 LECTURE .SURNAME%TYPE; 4 Arg3 LECTURE.NAME%TYPE ; 5 Arg4 LECTURE.CITY%TYPE; 6 Arg5 LECTURE.UNIV_ID%TYPE; 7 Cursor Curl IS SELECT * FROM LECTURE; 23
8 BEGIN 9 FETCH Curl INTO Arg1, Arg2, Arg3, Arg4, Arg5; 10 WHILE Cur1%FOUND LOOP 11 FETCH Curl INTO Arg1, Arg2, Arg3, Arg4, Arg5; 12 END LOOP; 13 EXCEPTION 14 WHEN INVALID_CURSOR THEN 15 DBMS_OUTPUT.PUT_LINE(' Hrb[dZ ijbeh`_gby. Hehldjuldmjkhj ' ) ; 16 END; 17 / Hrb[dZijbeh`_gby Hehldjuldmjkhj >ey h[jZ[hldb bkdexqbl_evguo kblmZpbc g_ \oh^ysbo \ i_j_q_gv klZg^Zjlguo fh`gh bkihevah\Zlv ci_pbZevguc h[jZ[hlqbd PL/SQL OTHERSbebhibkZlvihevah\Zl_evkdmx bkdexqbl_evgmxkblmZpbxbaZijh ]jZffbjh\Zlv __ h[jZ[hldm Dexq_\h_ keh\h OTHERS [ehdZ EXCEPTION hij_^_ey_l f_oZgbaf mgb\_jkZevghc h[jZ[hldb bkdexqbl_evguo kblmZpbc g_\hr_^rbo\kibkhdkblmZpbch[jZ[Zlu\Z_fuoy\gh \[ehd_ EXCEPTION. <\_^_f\l_dklijh]jZffuaZij_s_ggmxhi_jZpbx^_e_gbygZghevbh[jZ [hlZ_f^Zggmxbkdexqbl_evgmxkblmZpbx\kibkd_ OTHERS.GZkZfhf^_ e_ \ Oracle ij_^hij_^_e_gZ bkdexqbl_evgZy kblmZpby ZERO_DIVIDE, gh \ ^Zgghf ijbf_j_ wlh g_ \Z`gh Z \Z`gh lh qlh __ g_l \ kibkd_ [ehdZ EXCEPTION.) IJBF?J 4.3.2. SQL> DECLARE 2 Argl LECTURE. LECTURE _ID%TYPE; 3 Arg2 LECTURE .SURNAME%TYPE; 4 Arg3 LECTURE.NAME%TYPE ; 5 Arg4 LECTURE.CITY%TYPE; 6 Arg5 LECTURE.UNIV_ID%TYPE; 7 Cursor Curl IS SELECT * FROM LECTURE; 8 Arg6 NUMBER := 1; 9 BEGIN 10 Arg6 := Arg6/0. 0; 11 WHILE Curl%FOUND LOOP 12 FETCH Curl INTO Argl,Arg2,Arg3, Arg4, Arg5; 13 END LOOP; 14 EXCEPTION 15 WHEN INVALID_CURSOR THEN 16 DBMS_OUTPUT.PUT_LINE( 'Hrb[dZ ijbeh`_gby. Hehldjul dmjkhj 24
17 WHEN OTHERS THEN 18 DBMS_OUTPUT.PUT_LINE ('Hrb[dZ ijbeh`_gby. He^bZ]ghklb jh\ZggZyhrb[dZ 19 END; 20 / Bkdexqbl_evgZykblmZpbyhij_^_ey_fZyihevah\Zl_e_f^he`gZ[ulv hibkZgZ\[ehd_DECLARE ijh]jZffuBkihevam_lkyke_^mxsbckbglZdkbk hibkZgbybkdexqbl_evghckblmZpbb BfyBbkdexqbl_evghcBkblmZpbbEXCEPTION; < ijh]jZff_ mkeh\b_ \hagbdgh\_gby bkdexqbl_evghc kblmZpbb hij_^_ey_lky klZg^Zjlgufb kj_^kl\Zfb h[uqgh hi_jZlhjZfb IF …THEN. Ihke_h[gZjm`_gbymkeh\bc\hagbdgh\_gbybkdexqbl_evghckblmZpbbhgZ ]_g_jbjm_lkyhi_jZlhjhfRAISEdhlhjucbf__lke_^mxrbckbglZdkbk RAISE BfyBbkdexqbl_evghckblmZpbb Hi_jZlhj RAISE ]_g_jbjm_l bkdexqbl_evgmx kblmZpbx b i_j_^Z_l mijZ\e_gb_ gZ khhl\_lkl\mxsbc h[jZ[hlqbd bkdexqbl_evghc kblmZpbb dhlhjuc hij_^_eg \ [ehd_ EXCEPTION. < dZq_kl\_ ijbf_jZ \ jheb bkdexqbl_evghc kblmZpbb jZkkfhljbf ij_\ur_gb_ agZq_gby Argl ihjh]Z jZ\gh]h IJBF?J 4.3.3. SQL> DECLARE 2 Argl LECTURE. LECTURE _ID%TYPE; 3 Arg2 LECTURE .SURNAME%TYPE; 4 Arg3 LECTURE.NAME%TYPE ; 5 Arg4 LECTURE.CITY%TYPE; 6 Arg5 LECTURE.UNIV_ID%TYPE; 7 Special_case EXCEPTION; -- Ihevah\Zl_evkdZybkdexqbl_evgZykb lmZpby 8 Cursor Curl IS SELECT * FROM LECTURE ; 9 BEGIN 10 OPEN Curl; 11 FETCH Curl INTO Argl,Arg2,Arg3, Arg4, Arg5; 12 WHILE Curl%FOUND LOOP 13 FETCH Curl INTO Argl,Arg2,Arg3, Arg4, Arg5; 14 IF Argl > 20 15 THEN RAISE Special_case; 16 END IF; 17 END LOOP; 18 EXCEPTION 19 WHEN Special_case THEN 20 DBMS_OUTPUT.PUT_LINE('Ihevah\Zl_evkdZy 25
Bkdexqbl_evgZykblmZpby’); 21 WHEN OTHERS THEN 22 DBMS_OUTPUT.PUT_LINE('Orb[dZ ijbeh`_gby . He^b Z]ghklbjh\ZggZyhrb[dZ ); 23 END; 24 / AZ^Zgb_ 1. K^_eZlv\u[hjdmbalZ[ebpuSTUDENT kbkihevah\Zgb_fdmjkhjZbpbd eZ k f_lh^hf FOUND ^ey ihemq_gby ^Zgguo h klm^_glZo `b\msbo \ Fhkd\_ 2. K^_eZlv\u[hjdmbalZ[ebpu SUBJECT kbkihevah\Zgb_fdmjkhjZbpbd eZkf_lh^hfFOUND ^eyihemq_gby^Zgguohij_^f_lZo\h-hfk_f_ klj_ 3. K^_eZlv\u[hjdmbalZ[ebpu UNIVERSITY kbkihevah\Zgb_fdmjkhjZb pbdeZ k f_lh^hf FOUND ^ey ihemq_gby ^Zgguo h[ mgb\_jkbl_lZo k j_clbg]hf[hevrbf 4. K^_eZlv\u[hjdmbalZ[ebpu EXAM_MARKS kbkihevah\Zgb_fdmjkhjZ bpbdeZkf_lh^hfFOUND ^eyihemq_gby^Zgguo h[wdaZf_gZok^Zg guo\^Zggmx^Zlm 5. K^_eZlv \u[hjdm ba lZ[ebpu SUBJ_LECT k bkihevah\Zgb_f dmjkhjZ b pbdeZkf_lh^hfFOUND ^eyihemq_gby^Zgguohij_ih^Z\Zl_eyoqb lZxsboij_^f_lk^Zggufghf_jhf
4.4. Kha^Zgb_ihevah\Zl_evkdboijhp_^mjbnmgdpbc Ijhp_^mjubnmgdpbb —wlhh[t_dlu[Zau^Zgguob ke_^h\Zl_evghhgb kha^ZxlkydhfZg^hc CREATEbmgbqlh`ZxlkydhfZg^hc DROP.Ijbkha^Z gbbijhp_^mjubnmgdpbb ^he`gu[ulvhij_^_e_gubfyh[t_dlZi_j_q_gv b lbi iZjZf_ljh\ b eh]bdZ jZ[hlu ijhp_^mju beb nmgdpbb hibkZggu_ gZ yaud_ PL/SQL Qlh[ukha^Zlvijhp_^mjmbebnmgdpbxg_h[oh^bfh bf_lvkbkl_fgu_ ijb\be_]bb CREATE PROCEDURE.>ey cha^Zgby ijhp_^mju nmgdpbb beb iZd_lZ\ko_f_hlebqghc hl l_dms_c ko_fu ihevah\Zl_ey lj_[mxlky kbk l_fgu_ijb\be_]bb CREATE ANY PROCEDURE. Ihke_hij_^_e_gbybf_gb gh\hcijhp_^mjubebnmgdpbbg_h[oh^bfhaZ^Zlv__bf_gZlbiub\b^uiZ jZf_ljh\ >ey dZ`^h]h iZjZf_ljZ ^he`_g [ulv mdZaZg h^bg ba \b^h\ iZjZ f_ljZ — IN, OUTbeb IN OUT.
gbyiZjZf_ljZ\ijhp_kk_jZ[hluijhp_^mjulh_klviZjZf_lj\b^ZHUL — wlh \ha\jZsZ_fuc iZjZf_lj IZjZf_lj IN OUT — wlh iZjZf_lj dhlhjhfm ijb\uah\_^he`gh[ulvijbk\h_ghagZq_gb_dhlhjh_fh`_l[ulvbaf_g_gh \ l_e_ ijhp_^mju IZjZf_lju ijhp_^mj beb nmgdpbc bf_xl \b^u ijbk\h _ggu_ihmfheqZgbx >hihegbl_evghdhij_^_e_gbyfg_h[oh^bfuf^eyijhp_^mju\hij_ ^_e_gbb nmgdpbb ^he`_g [ulv mdZaZg lbi ^Zgguo _^bgkl\_ggh]h \ha\jZ sZ_fh]hnmgdpb_cagZq_gby CREATE OR REPLACE PROCEDURE InsRec 2 (Argl IN NUMBER, Arg2 IN NUMBER) 3 AS 4 Coeff CONSTANT NUMBER := 0.5; 5 BEGIN 6 INSERT INTO SUBJ_LECT VALUES (Coeff*Argl, Coeff*Arg2 ); 7 END; 8/ Bkiheg_gb_kha^Zgghcijhp_^mju InsRecfh`_l[ulv\uiheg_ghhi_jZ
27
lhjhf?O?KyaudZ PL/SQL.Ihke_^mxsZy\u[hjdZbalZ[ebpuSUBJ_LECT beexkljbjm_lbaf_g_gby\[Za_^Zgguohkms_kl\e_ggu_\uah\hfijhp_^m ju InsRec. SQL> exec InsRec (240,120); Qlh[u mlhqgblv \uy\e_ggu_ \ ijhp_kk_ kbglZdkbq_kdh]h ZgZebaZ hrb[dbfh`gh\hkihevah\ZlvkydhfZg^hc PL/SQL SHOW ERRORS.WlZ dh fZg^Z ihdZau\Z_l hrb[db, h[gZjm`_ggu_ \ ijhp_kk_ \uiheg_gby CREATE PROCEDURE, CREATE FUNCTION, CREATE PACKAGE, CREATE PACKAGE BODY b CREATE TRIGGER. ?kebdhfZg^Z SHOW ERRORSbk ihevam_lky[_aiZjZf_ljh\lh\ha\jZsZxlkyhrb[dbihke_^g_cdhfibebjh \Zgghcijhp_^mjunmgdpbbiZd_lZl_eZiZd_lZbebljb]]_jZ JZkkfhljbfijbf_jh[gZjm`_gbybbkijZ\e_gbyhrb[db<ijhp_^mj_ ij_^klZ\e_gghc\ur_,^h[Z\bfhrb[hqguchi_jZlhjbaf_gyxsbcagZq_gb_ iZjZf_ljZ\b^ZINdhlhjucg_^he`_gbaf_gylvky IJBF?J 4.4.2. SQL> CREATE OR REPLACE PROCEDURE InsRec 2 (Argl IN NUMBER, Arg2 IN NUMBER) 3 AS 4 Coeff CONSTANT NUMBER := 0.5; 5 BEGIN 6 Arg1:=Arg1 + 200; 7 INSERT INTO SUBJ_LECT VALUES (Coeff*Argl, Coeff*Arg2 ); 8 END; 9/ SQL> show errors Errors for PROCEDURE INSREC: LINE/COL ERROR 6/1 PLS-00363: expression 'ARGl' cannot be used as an assignment target 6/1 PL/SQL: Statement ignored GZihfgbf qlh nmgdpbb PL/SQL hlebqZxlky hl ijhp_^mj l_fqlh\ha \jZsZxl\\uau\Zxsmxkj_^magZq_gb_iZjZf_ljZ Hi_jZlhj hij_^_e_gby nmgdpbb Oracle bkihevam_l ke_^mxsbc kbglZd kbk CREATE [OR REPLACE] FUNCTION [bfyBko_fu]bfyBnmgdpbb [(bfyBiZjZf_ljZ [{IN I OUT I INOUT}] lbiB^Zgguo [bfyBiZjZf_ljZ [{IN I OUT I INOUT}] lbiBB^Zgguo ...])] RETURN lbi_^Zgguo {IS I AS} QSR]SDffDBQDB3/64/ HibkZgb_lbiZ^Zgguo^ey\ha\jZsZ_fh]hnmgdpb_cagZq_gbylj_[m 28
_lkyh[yaZl_evgh IjbhibkZgbbi_j_f_gguonmgdpbblZd`_dZdbijb hib kZgbbi_j_f_gguoijhp_^mjug_bkihevam_lkydexq_\h_ keh\h DECLARE. ;ehdhij_^_e_gby^ZgguogZqbgZ_lkykjZam ihke_dexq_\h]hkeh\Z ISbeb AS,ih\u[hjmihevah\Zl_ey JZkkfhljbfijbf_jkha^ZgbynmgdpbbdhlhjZy\uqbkey_lkmffmagZ q_gbc Zljb[mlh\ lZdbo qlh h^bg ba Zljb[mlh\ ihiZ^Z_l \ aZ^Zgguc iZjZ f_ljZfbnmgdpbbbgl_j\ZeImklvlZ[ebpZ knhjfbjh\ZgZij_^eh`_gb_f IJBF?J 4.4.3. SQL> CREATE OR REPLACE FUNCTION SumRecInt 2 (Argl IN NUMBER, Arg2 IN NUMBER) 3 RETURN NUMBER 4 AS 5 Sum_Var NUMBER := 0.0; 6 BEGIN 7 SELECT Sum(LECTURE_ID) INTO Sum_Var FROM SUBJ_LECT WHERE SUBJ_ID BETWEEN Argl AND Arg2; 8 RETURN Sum_Var; 9 END; 10 / Function created. ?keb oZjZdl_j bkihevah\Zgby ijbeh`_gbc baf_gbeky lh ^ey hk\h[h` ^_gby j_kmjkh\ [Zau ^Zgguo fh`_l ihlj_[h\Zlvky mgbqlh`blv ijhp_^mjm beb nmgdpbx < kh[kl\_gghc ko_f_ ihevah\Zl_ex g_ lj_[mxlky ^hihegb l_evgu_ijb\be_]bb^eymgbqlh`_gbyijhp_^mjubebnmgdpbb>eymgbqlh`_gby ijhp_^mju beb nmgdpbb \ ko_f_ ^jm]h]h ihevah\Zl_ey g_h[oh^bfh gZebqb_ijb\be_]bb DROP ANY PROCEDURE. >eymgbqlh`_gbyijhp_^mju Oraclebkihevam_lke_^mxsbckbglZdkbk DROP PROCEDURE [bfyBko_fu]bfyBijhp_^mju JZkkfhljbfijbf_jmgbqlh`_gbynmgdpbb Oracle. SQL > DROP FUNCTION SumRecInt Function dropped; AZ^Zgb_ 2 1. HibkZlvijhp_^mjmdhlhjZyaZghkbl^Zggu_\lZ[ebpm STUDENT \aZ\b kbfhklbhliZjZf_ljh\ijhp_^mju\ua\Zlvwlmijhp_^mjm 2. HibkZlv ijhp_^mjm dhlhjZy aZghkbl ^Zggu_ \ lZ[ebpu STUDENT b EXAM_MARKSkkh[ex^_gb_fkkuehqghcp_ehklghklb\hkihevah\Zlvky _c\aZ\bkbfhklbhliZjZf_ljh\ 3. HibkZlv ijhp_^mjm dhlhjZy aZghkbl ^Zggu_ \ lZ[ebpu STUDENT b SUBJECT k kh[ex^_gb_f kkuehqghc p_ehklghklb \hkihevah\Zlvky _c \ aZ\bkbfhklbhliZjZf_ljh\ 29
4. HibkZlv ijhp_^mjm dhlhjZy aZghkbl ^Zggu_ \ lZ[ebpu STUDENT b UNIVERSITYkkh[ex^_gb_fkkuehqghcp_ehklghklb\hkihevah\Zlvky_c \aZ\bkbfhklbhliZjZf_ljh\ 5. HibkZlvijhp_^mjmdhlhjZyaZghkbl^Zggu_\lZ[ebpmLECTURE \aZ\b kbfhklbhliZjZf_ljh\ijhp_^mju\ua\Zlvwlmijhp_^mjm 6. HibkZlv b \ua\Zlv nmgdpbx dhlhjZy \uqbkey_l kmffm [Zeeh\ ^ey klm^_glh\ ghf_jZ dhlhjuo gZoh^ylky \ aZ^Zgghf bgl_j\Ze_ \ lZ[ebp_ EXAM_MARKS. 7. HibkZlv b \ua\Zlv nmgdpbx dhlhjZy \uqbkey_l kmffm [Zeeh\ \ g_dhlhjuc^_gvih^Zgghfmij_^f_lm\lZ[ebp_EXAM_MARKS. 8. HibkZlv b \ua\Zlv nmgdpbx dhlhjZy \uqbkey_l ^ey klm^_glh\ ghf_jZ dhlhjuogZoh^ylky\^Zgghf^bZihahg_fZdkbfZevguc[ZeeihaZ^Zgghfm ij_^f_lmkg_dhlhjufghf_jhf \lZ[ebp_EXAM_MARKS. 9. HibkZlv b \ua\Zlv nmgdpbx dhlhjZy hij_^_ey_l ^ey klm^_glh\ k aZ^Zgghc nZfbeb_c kmffm [Zeeh\ ih aZ^Zgghfm ij_^f_lm \ lZ[ebp_ EXAM_MARKS.
4.5. IZd_lu PL/SQL Ijhp_^mjunmgdpbbb]eh[Zevgu_i_j_f_ggu_h[t_^bg_ggu_h[sbf nmgdpbhgZevguf aZfukehf qZklh hnhjfeyxl \ \b^__^bgh]hh[t_dlZ[Zau ^Zgguo — iZd_lZHkh[_gghklvxiZd_lh\PL/SQLy\ey_lkyjZa^_evgZydhf ibeypby b ojZg_gb_ bgl_jn_ckghc b bkihegbl_evghc qZkl_c iZd_lZ IZd_l dZdh[t_dlkhklhblba^\moqZkl_cki_pbnbdZpbbiZd_lZbl_eZiZd_lZ< ki_pbnbdZpbbiZd_lZojZgblkyhibkZgb_ijhp_^mjnmgdpbc]eh[Zevguoi_ j_f_gguo dhgklZgl b dmjkhjh\ dhlhju_ ^hklmigu ^ey \g_rgbo ijbeh`_ gbc < l_e_ iZd_lZ hij_^_eyxlky \k_ ijhp_^mju nmgdpbb b i_j_f_ggu_ \dexqZy l_ dhlhju_ g_ [ueb hij_^_e_gu \ ki_pbnbdZpbb iZd_lZ Ijhp_^mjunmgdpbbbi_j_f_ggu_hij_^_e_ggu_\l_e_iZd_lZghg_hibkZggu_ \_]hki_pbnbdZpbby\eyxlkyehdZevgufb
30
CREATE [OR REPLACE] PACKAGE [bfy_ko_fu.]bfy_iZd_lZ {IS I AS} ki_pbnbdZpbyBiZd_lZBgZBPL/SQL Dexq_\h_ keh\h OR REPLACE mdZau\Z_l gZ [_amkeh\gh_ aZf_s_gb_ klZjh]hl_dklZki_pbnbdZpbbiZd_lZ?kebdexq_\h_keh\h OR REPLACEg_ mdZaZghbiZd_lhij_^_e_g\kbkl_f_lhaZf_s_gbyklZjh]hagZq_gbyki_pb nbdZpbbiZd_lZg_ijhbkoh^blb\ha\jZsZ_lkykhh[s_gb_h[hrb[d_Ki_ pbnbdZpbyiZd_lZgZqbgZ_lkykhibkZgbydhgklZglbi_j_f_gguoIjbhib kZgbbi_j_f_gguoiZd_lZdexq_\h_keh\h DECLAREg_bkihevam_lky JZkkfhljbfijbf_jkha^Zgbyki_pbnbdZpbbiZd_lZdhlhjZykhklhbl bahibkZgbydhgklZglunmgdpbbbijhp_^mju IJBF?J 4.5.1. SQL> CREATE OR REPLACE PACKAGE PAC 2 AS 3 PAC_CONST CONSTANT NUMBER := 20; 4 FUNCTION MUL(Argl NUMBER, Arg2 NUMBER) 5 RETURN NUMBER; 6 PROCEDURE AUDIT; 7 END; 8/ Hi_jZlhjhij_^_e_gbybkihegbl_evghcqZklbl_eZ iZd_lZ Oraclebk ihevam_lke_^mxsbckbglZdkbk CREATE [OR REPLACE] PACKAGE BODY [bfyBko_fu]bfyBiZd_lZ {IS I AS} FQHpbnbdZpbyBQDdHPDBgDB3/64/ Dexq_\h_ keh\h OR REPLACE mdZau\Z_l gZ [_amkeh\gh_ aZf_s_gb_ klZjh]hl_dklZl_eZiZd_lZ?kebdexq_\h_ ; keh\h OR REPLACEg_mdZaZgh biZd_lhij_^_e_g\kbkl_f_lhaZf_s_gbyklZjh]hagZq_gbyl_eZiZd_lZg_ ijhbkoh^blb\ha\jZsZ_lkykhh[s_gb_h[hrb[d_ Hij_^_e_gb_ l_eZ iZd_lZ gZqbgZ_lky k hibkZgby dhgklZgl b i_j_f_g guoDhgklZglubi_j_f_ggu_hibkZggu_\ki_pbnbdZpbbiZd_lZy\eyxlky ]eh[Zevgufb b \ l_e_ iZd_lZ ih\lhjgh g_ hibku\Zxlky IjbhibkZgbbdhg klZglbi_j_f_gguoiZd_lZdexq_\h_keh\h DECLAREg_bkihevam_lky JZkkfhljbfijbf_jkha^Zgbyl_eZiZd_lZki_pbnbdZpbydhlhjh]hijb \_^_gZ\ur_.ImklvnmgdpbyiZd_lZ MUL\uihegy_lmfgh`_gb_Zj]mf_glh\ gZdhgklZglmiZd_lZZijhp_^mjZ AUDITnbdkbjm_lnZdlh[jZs_gbydnmgd pbb MULaZibkvx\lZ[ebpmagZq_gbykq_lqbdZh[jZs_gbcbl_dms_c^Zlu Ij_^iheZ]Z_lky qlh lZ[ebpZ TabAUD k khhl\_lkl\mxsbfb lbiZfb ^Zgguo 31
Zljb[mlh\dfhf_glmkha^Zgbyl_eZiZd_lZkha^ZgZIjhlhdhekha^Zgbyl_eZ iZd_lZijb\_^_ggb`_ IjbhibkZgbbnmgdpbcbijhp_^mjiZd_lZ\hlebqb_hlhibkZgbch^b ghqguonmgdpbcbijhp_^mjhi_jZlhj CREATEg_bkihevam_lky IJBF?J 4.5.2. SQL> CREATE OR REPLACE PACKAGE BODY PAC 2 AS 3 PAC_COUNT NUMBER := 0; 4 FUNCTION MUL(Argl NUMBER, Arg2 NUMBER) 5 RETURN NUMBER IS 6 BEGIN 7 AUDIT; 8 RETURN Arg1* PAC_CONST + Arg2*PAC_CONST; 9 END; 10 PROCEDURE AUDIT IS 11 BEGIN 12 PAC_COUNT := PAC_COUNT + 1; 13 INSERT INTO TabAUD VALUES ( PAC_COUNT, SYSDATE ) ; 14 COMMIT; 15 END; 16 END; 17 / Package body created. DhgklZglZbebi_j_f_ggZyhibkZggZy\ki_pbnbdZpbbiZd_lZfh`_l [ulv ^hklmigZ ba ihevah\Zl_evkdhc ijh]jZffu dhg_qgh _keb ijhp_^mj_ bebnmgdpbblZdhc^hklmijZaj_r_g Qlh[uh[jZlblvkyd]eh[Zevghci_j_ f_gghcbebdhgklZgl_iZd_lZgm`ghmdZaZlv\dZq_kl\_ij_nbdkZbfyiZd_ lZ Gb`_ ijb\_^_g ijbf_j beexkljbjmxsbc \hafh`ghklv ^hklmiZ d ]eh [Zevghc dhgklZgl_ iZd_lZ b g_\hafh`ghklv ^hklmiZ d qZklghc i_j_f_gghc iZd_lZ SQL>EXEC DBMS_OUTPUT.PUT_LINE(PAC.PAC_CONST); 20.0 PL/SQL procedure successfully completed. SQL>EXEC DBMS_OUTPUT.PUT_LINE ( PAC.PAC_COUNT ) ; begin dbms_output.put_line (pac. pac_count) ; end; ERROR at line 1; 32
ORA-06550: line I, column 34: PLS-00302: component 'PAC_COUNT' must be declared ORA-06550: line I, column 7: PL/SQL: Statement ignored Qlh[u\ua\Zlvijhp_^mjmbebnmgdpbxiZd_lZ\\uah\_gm`ghmdZaZlv \dZq_kl\_ij_nbdkZbfyiZd_lZ <aZdexq_gb_jZa^_eZjZkkfhljbfijbf_jbkihevah\Zgbynmgdpbbkha ^Zggh]hiZd_lZ SQL>EXEC DBMS_OUTPUT.PUT_LINE(PAC.MUL(lll,222)); PL/SQL procedure successfully completed. Ijb bkihevah\Zgbb i_j_f_gguo iZd_lZ bgbpbZebaZpby ehdZevguo i_ j_f_gguo iZd_lZ ijhbkoh^bl ijb aZimkd_ k_j\_jZ Oracle. < ^Zgghf kemqZ_ ihke_ hklZgh\Z b ih\lhjgh]h aZimkdZ k_j\_jZ kq_lqbd h[jZs_gbc PAC_COUNT[m^_lmklZgh\e_g\gme_\h_khklhygb_?kebihkfukemj_rZ_ fhcaZ^Zqblj_[m_lkyg_aZ\bkbfh_hlhklZgh\h\k_j\_jZijbjZs_gb_kq_lqb dZfh`gh \hkihevah\ZlvkylZdbfh[t_dlhfdZdihke_^h\Zl_evghklv >eyhk\h[h`^_gbyj_kmjkh\k_j\_jZfh`_lihlj_[h\Zlvkymgbqlh`blv iZd_l < kh[kl\_gghc ko_f_ ihevah\Zl_ex g_ lj_[mxlky ^hihegbl_evgu_ ijb\be_]bb^eymgbqlh`_gbyiZd_lZ>eymgbqlh`_gbyiZd_lZ\ko_f_^jm]h ]hihevah\Zl_eyg_h[oh^bfZijb\be_]by DROP ANY PROCEDURE. >eymgbqlh`_gbyki_pbnbdZpbbiZd_lZbl_eZiZd_lZ Oraclebkihevam _lke_^mxsbckbglZdkbk DROP PACKAGE [BODY] [bfyBko_fu.]bfyBiZd_lZ G_h[yaZl_evgh_dexq_\h_keh\h BODYmdZau\Z_lqlh mgbqlh`Z_lkylhevdh l_ehiZd_lZ?kebdexq_\h_keh\h BODYhims_ghlhm^Zey_lkybki_pbnb dZpbybl_ehiZd_lZIZjZf_ljbfyBiZd_lZaZ^Z_lbfymgbqlh`Z_fh]hiZd_ lZIjbf_jmgbqlh`_gbyiZd_lZjZkkfZljb\Z_lkygb`_ SQL > DROP PACKAGE PAC; Package dropped, AZ^Zgb_ 1. Kha^ZlviZd_lkhklhysbcbanmgdpbbkiZjZf_ljZfbijhp_^mju[_aiZ jZf_ljh\ Nmgdpby ih^kqblu\Z_l dhebq_kl\h klm^_glh\ ihemqZxsbo klbi_g^bx aZ^Zggmx iZjZf_ljhf Ijhp_^mjZ ih^kqblu\Z_l dhebq_kl\h h[jZs_gbcdnmgdpbbbaZghkblwlhdhebq_kl\h\_ebqbgmklbi_g^bbdh ebq_kl\h klm^_glh\ ihemqZxsbo \ __ \gh\mxlZ[ebpmkha^ZggmxaZjZ g__ 2. Kha^ZlviZd_lkhklhysbcbanmgdpbbkiZjZf_ljZfbijhp_^mju[_aiZ jZf_ljh\Nmgdpbyih^kqblu\Z_ldhebq_kl\hklm^_glh\`b\msbo\]hjh ^_ aZ^Zgghf iZjZf_ljhf Ijhp_^mjZ ih^kqblu\Z_l dhebq_kl\h h[jZs_ gbc d nmgdpbb b aZghkbl wlh dhebq_kl\h gZa\Zgb_ ]hjh^Z dhebq_kl\h 33
3.
4.
5.
6.
klm^_glh\`b\msbo\wlhf]hjh^_\gh\mxlZ[ebpmkha^ZggmxaZjZg__. Kha^ZlviZd_lkhklhysbcbanmgdpbbkiZjZf_ljZfbijhp_^mju[_aiZ jZf_ljh\Nmgdpbyih^kqblu\Z_ldhebq_kl\hij_^f_lh\ihdhlhjufih emq_ghhp_gdZaZ^ZggZyiZjZf_ljhf[he__q_fmq_eh\_dIjhp_^mjZ ih^kqblu\Z_ldhebq_kl\hh[jZs_gbcdnmgdpbbbaZghkblwlhdhebq_kl\h \_ebqbgmhp_gdbbdhebq_kl\hij_^f_lh\\gh\mxlZ[ebpmkha^ZggmxaZ jZg__ Kha^ZlviZd_lkhklhysbcbanmgdpbbkiZjZf_ljZfbijhp_^mju[_aiZ jZf_ljh\Nmgdpbyih^kqblu\Z_ldhebq_kl\hmgb\_jkbl_lh\kj_clbg]hf aZ^ZggufiZjZf_ljhfIjhp_^mjZih^kqblu\Z_ldhebq_kl\hh[jZs_gbcd nmgdpbb b aZghkbl wlh dhebq_kl\h \_ebqbgm j_clbg]Z dhebq_kl\h mgb \_jkbl_lh\kwlbfj_clbg]hf\gh\mxlZ[ebpmkha^ZggmxaZjZg__ Kha^ZlviZd_lkhklhysbcbanmgdpbbkiZjZf_ljZfbijhp_^mju[_aiZ jZf_ljh\ Nmgdpby ih^kqblu\Z_l dhebq_kl\h ij_ih^Z\Zl_e_c jZ[hlZx sbo\mgb\_jkbl_l_aZ^ZggufiZjZf_ljhfIjhp_^mjZih^kqblu\Z_ldh ebq_kl\hh[jZs_gbcdnmgdpbbbaZghkblwlhdhebq_kl\hghf_jmgb\_j kbl_lZdhebq_kl\hij_ih^Z\Zl_e_c\gh\mxlZ[ebpmkha^ZggmxaZjZg__ Kha^ZlviZd_lkhklhysbcbanmgdpbbkiZjZf_ljZfbijhp_^mju[_aiZ jZf_ljh\ Nmgdpby ih^kqblu\Z_l dhebq_kl\h ij_^f_lh\ ijhqblZgguo \ k_f_klj_ghf_jdhlhjh]haZ^ZgiZjZf_ljhfkdhebq_kl\hfqZkh\aZ^Zg guf^jm]bfiZjZf_ljhfIjhp_^mjZih^kqblu\Z_ldhebq_kl\hh[jZs_gbc dnmgdpbbbaZghkblwlhdhebq_kl\hghf_jk_f_kljZdhebq_kl\hqZkh\b dhebq_kl\hij_^f_lh\\gh\mxlZ[ebpmkha^ZggmxaZjZg__
Ljb]]_ju[Zau^Zgguo Ljb]]_j[Zau^Zgguo —wlhijhp_^mjZ PL/SQL,dhlhjZyZ\lhfZlbq_kdb aZimkdZ_lkyijb\hagbdgh\_gbbhij_^_e_gguokh[ulbck\yaZgguok\uihe g_gb_fhi_jZpbc\klZ\dbm^Ze_gbybebfh^bnbdZpbb^ZgguolZ[ebpuKh [ulb_ mijZ\eyxs__ aZimkdhf ljb]]_jZ hibku\Z_lky \ \b^_eh]bq_kdbomk eh\bcDh]^Z\hagbdZ_lkh[ulb_khhl\_lkl\mxs__mkeh\byfljb]]_jZk_j\_j Oracle Z\lhfZlbq_kdb aZimkdZ_l ljb]]_j lh _klv bgl_jij_lbjm_l dh^ ijh ]jZffuljb]]_jZaZibkZggucgZyaud_ PL/SQL. H[uqgh ljb]]_ju bkihevamxl ^ey \uiheg_gby keh`guo ijh\_jhd h] jZgbq_gbc p_ehklghklb fgh]hZki_dlguo ijh\_jhd \uiheg_gby ijZ\be jZa ]jZgbq_gby^hklmiZbli Ljb]]_jaZimkdZ_lkyijb\uiheg_gbbh^ghcbalj_ohi_jZpbcbaf_g_ gbykh^_j`bfh]hlZ[ebpu INSERT, DELETEbeb UPDATE.Ljb]]_jfh`_l aZimkdZlvkybg_kdhevdbfbhi_jZlhjZfbghohly[uh^bghi_jZlhjbaljhcdb ^he`_g[ulvh[yaZl_evghmdZaZg\mkeh\bbaZimkdZljb]]_jZ?kebi_j_q_gv hi_jZlhjh\aZimkdZxsboljb]]_j\dexqZ_lhi_jZlhj UPDATE,lh^eymkeh \bckjZ[Zlu\Zgbyfh]ml[ulvmdZaZgudhgdj_lgu_baf_gy_fu_klhe[pu Dh^ljb]]_jZfh`_l\uihegylvkyeb[h^heb[hihke_l_ohi_jZlhjh\ 34
dhlhju_bgbpbbjh\ZebaZimkdljb]]_jZGZijbf_j_kebljb]]_jaZimkdZ_lky ^ey ijh\_jdb iheghfhqbcihevah\Zl_eygZijZ\h\uiheg_gbyhi_jZpbblh dhg_qghgm`ghbkihevah\Zlvljb]]_jkaZimkdhf^h\uiheg_gbyhi_jZpbbk dexq_\uf keh\hf BEFORE). ?keb ljb]]_j ijbf_gy_lky ^ey nhjfbjh\Zgby ^Zgguo^eyZm^blhjkdhcaZibkblhjZamfghbkihevah\Zlvljb]]_jkaZimkdhf ihke_\uiheg_gbyhi_jZpbb kdexq_\ufkeh\hf AFTER). Dh^ ljb]]_jZ fh`_l [ulv Zkkhpbbjh\Zg eb[hkhi_jZpb_cgZ^lZ[eb p_c\p_ehfeb[hkdZ`^hckljhdhcgZ^dhlhjhc\uihegy_lkyhi_jZpby< aZ\bkbfhklb hl wlh]h ljb]]_ju ih^jZa^_eyxl gZ hi_jZlhjgu_ ljb]]_ju b kljhqgu_ ljb]]_ju Hi_jZlhjgu_ ljb]]_ju h[uqgh bkihevamxl ^ey ijh \_jdb ijZ\be jZa]jZgbq_gby ^hklmiZ hi_jbjmxsbo lZ[ebp_c \ p_ehf Z kljhqgu_ljb]]_juqZklhbkihevamxl^ey ijh\_jdbh]jZgbq_gbcp_ehklgh klb ijb \klZ\d_ kljhd Mkeh\b_ aZimkdZ kljhqgh]h ljb]]_jZ fh`_l [ulv mlhqg_gh^hihegbl_evgufeh]bq_kdbfmkeh\b_f Qlh[u kha^Zlv ljb]]_j g_h[oh^bfh bf_lv kbkl_fgu_ ijb\be_]bb CREATE TRIGGER. >ey kha^Zgby ljb]]_jZ \ ko_f_ hlebqghc hl l_dms_c ko_fu ihevah\Zl_ey lj_[mxlky kbkl_fgu_ ijb\be_]bb CREATE ANY TRIGGER. Hi_jZlhj hij_^_e_gby ljb]]_jZ Oracle bkihevam_l ke_ ^mxsbckbglZdkbk CREATE[ OR REPLACE] TRIGGER [bfy ko_fu. ]bfy_ljb]]_jZ {BEFORE I AFTER} {INSERT I DELETE I UPDATE [OF bfy_klhe[pZ [, bfy_klhe[pZ ... ]] } [OR {INSERT I DELETE I UPDATE [OF bfy_klhe[pZ [, bfyBklhe[pZ ]]}...] ON [bfyBko_fu]{bfyBlZ[ebpu I bfyBij_^klZ\e_gby } [FOR EACH ROW] [WHEN mkeh\b_ ] FQHpbnbdZpbbBQDdHPDBgDB3L/SQL Dexq_\h_ keh\h OR REPLACE mdZau\Z_l gZ [_amkeh\gh_ aZf_s_gb_ klZjh]h l_dklZ ljb]]_jZ ?keb dexq_\h_ keh\h OR REPLACE g_ mdZaZgh b ljb]]_j hij_^_e_g \ kbkl_f_ lh aZf_s_gby klZjh]h agZq_gby ljb]]_jZ g_ ijhbkoh^blb\ha\jZsZ_lkykhh[s_gb_h[hrb[d_ Dexq_\u_ keh\Z BEFOREbeb AFTERmdZau\ZxlgZ\uiheg_gb_dh^Z ljb]]_jZeb[h^heb[hkhhl\_lkl\_gghihke_hi_jZlhjh\fZgbimebjh\Zgby ^Zggufbbgbpbbjh\Z\rboaZimkdljb]]_jZ Dexq_\u_keh\Z INSERT, DELETEbeb UPDATE hij_^_eyxldhgdj_l guc hi_jZlhj aZimkdZxsbc ljb]]_j >ey hi_jZlhjZ UPDATE fh]ml [ulv mdZaZgu klhe[pu baf_g_gb_ dhlhjuo aZimkdZ_l ljb]]_j ?keb dhgdj_lgu_ klhe[pug_mdZaZgulhljb]]_jaZimkdZ_lbaf_g_gb_ex[h]hklhe[pZG_h[y aZl_evgh_ dexq_\h_ keh\h OR ijbkh_^bgy_l ^hihegbl_evguc hi_jZlhj aZ imkdZxsbcljb]]_j Dexq_\h_ keh\h ON aZ^Z_l bfy lZ[ebpu beb ij_^klZ\e_gby Zkkhpbb jh\Zggh]hkljb]]_jhf G_h[yaZl_evgh_dexq_\h_keh\h ON EACH ROWhij_^_ey_lljb]]_j dZdkljhqguc 35
G_h[yaZl_evgh_dexq_\h_keh\h WHENaZ^Z_l^hihegbl_evgh_eh]bq_ kdh_mkeh\b_km`Zxs__h[eZklv^_ckl\byljb]]_jZ Ij_`^_q_fi_j_clbdijbf_jmihkljh_gbyljb]]_jZijb\_^_fg_dhlh ju_ ^hihegbl_evgu_ k\_^_gby h[ h[jZ[hld_ bkdexqbl_evguo kblmZpbc \ Oracle. >ey ih^dexq_gby d f_oZgbafm h[jZ[hldb hrb[hd ihevah\Zl_evkdbo lhq_d \oh^Z ijbf_gy_lky ijhp_^mjZ RAISE_APPLICATION_ERROR. K __ ihfhsvxfh`ghh[jZ[hlZlv^h 1000hij_^_ey_fuoihevah\Zl_e_fhrb[hdk ghf_jZfb \ ^bZiZahg_ hl -20000 ^h -20999. CREATE OR REPLACE TRIGGER TRIG_TBI 2 BEFORE INSERT ON LZb1 3 FOR EACH ROW 4 DECLARE 5 StatAvg NUMBER; 6 StatN NUMBER; 7 BEGIN 8 SELECT COUNT(Atl),SUM(At1) INTO StatN, StatAvg 9 FROM Tab1; 10 IF (ABS (StatAvg - StatN* (: new .Alt1)) > 30) 11 THEN RAISE_APPLICATION_ERROR (-20002, ' Kebrdhf [hevrh_ mdehg_gb_ ' ); 12 END IF; 13 END; 14 / Trigger created.
36
JZ[hlm f_oZgbafZ ljb]]_jZ ijhbeexkljbjm_f gZ ijbf_j_ Ijb \\h^_ agZq_gby^hklZlhqgh[ebadh]hdkj_^g_fm\^ZgghfkemqZ_ 40),ljb]]_jg_ aZimkdZ_lkybgbq_]hg_ijhbkoh^blIjb\\h^_agZq_gbyZljb[mlZjZ\gh ]h 90,khhl\_lkl\mxsZyklZlbklbdZmdZau\Z_lgZ[hevrh_mdehg_gb_ijhbkoh^bl kjZ[Zlu\Zgb_ ljb]]_jZ b gh\Zy kljhdZ g_ \dexqZ_lky Hi_jZpby \u [hjdbih^l\_j`^Z_lh`b^Z_fh_baf_g_gb_\lZ[ebp_ SQL> insert into tab1 values (40); I row created. SQL> insert into tab1 values (90); insert into tab1 values (90) ERROR at line 1: ORA-20002:Kebrdhf[hevrh_mdehg_gb_ ORA-06512: at "SYSTEM. TRIG_TBI", line 9 ORA-04088: error during execution of trigger 'SYSTEM .TRIG_TBI' SQL> select * from tab1; Ke_^mxsbc ijbf_j beexkljbjm_l \hafh`ghklv h[jZ[hldb bkdexqb l_evghc kblmZpbb kj_^kl\Zfb ihevah\Zl_evkdhc ijh]jZffu < ^Zgghf kem qZ_kha^Z_lkyljb]]_jdhlhjucijbij_\ur_gbbaZ^Zggh]hihjh]Zmdehg_ gby\\h^bfh]hagZq_gbyZljb[mlZ\u\h^bl^bZ]ghklbq_kdh_khh[s_gb_Ijb wlhf^Zggu_\lZ[ebpm\\h^ylky IJBF?J SQL> CREATE OR REPLACE TRIGGER TRIG_TB2 2 BEFORE INSERT ON LZb1 3 FOR EACH ROW 4 DECLARE 5 StatAvg NUMBER; 6 StatN NUMBER; 7 Special_case EXCEPTION; --Ihevah\Zl_evkdZybkdexqbl_evgZykb lmZpby 8 BEGIN 9 SELECT COUNT(Atl),SUM(AtI) INTO StatN, StatAvg 10 FROM Tab1; 11 IF (ABS (StatAvg - StatN* (: new. Atl)) > 30) 12 THEN RAISE Special_case; 13 END IF; 14 EXCEPTION 15 WHEN Special_case THEN 16 DBMS_OUTPUT. PUT_LINE ( 'Kebrdhf[hevrh_mdehg_gb_ '); 17 WHEN OTHERS THEN 18 DBMS_OUTPUT. PUT_LINE ( ' He^bZ]ghklbjh\ZggZyhrb[dZljb]]_jZ ' ); 37
19 END; 20 / Trigger created. Ijb \\h^_ agZq_gby Zljb[mlZ jZ\gh]h 90 ijhbkoh^bl kjZ[Zlu\Zgb_ ljb]]_jZ TRIG_TB2. insert into tabl values(90); Kebrdhf[hevrh_mdehg_gb_ < hlebqb_ hl ijhp_^mj nmgdpbc b iZd_lh\ k_j\_j Oracle g_ ojZgbl dh^ljb]]_jZ\\b^_kdhfibebjh\Zggh]h[ehdZ PL/SQL.Ijbi_j\hfaZimkd_ ljb]]_jZ_]hdh^kqblu\Z_lkybakeh\Zjy^Zgguodhfibebjm_lkybkdhfib ebjh\ZggZy\_jkbykhojZgy_lky\h[eZklb SGA.Ihwlhfm^eyqZklhbkihev am_fuo ljb]]_jh\ p_e_khh[jZagh dh^ hl\_qZxsbc aZ ijhp_^mjgmx qZklv ljb]]_jZ\dexqZlv\ojZgbfmxijhp_^mjmZ\l_e_ljb]]_jZhklZ\eylvlhev dhaZibkvmkeh\bc aZimkdZb\uah\ukhhl\_lkl\mxsboijhp_^mjbnmgdpbc GZij_^eh`_gbyyaudZ SQL,\dexq_ggu_\dh^ljb]]_jZ Oracle,gZeh `_guke_^mxsb_h]jZgbq_gbyL_ehljb]]_pag_fh`_l\dexqZlv\k_[yy\ gh_ bkihevah\Zgb_ mijZ\eyxsbo hi_jZlhjh\ COMMIT, ROLLBACK b SAVEPOINT, hi_jZlhjh\ yaudZ hij_^_e_gby ^Zgguo CREATE, ALTER b DROP, hi_jZlhjh\ mijZ\eyxsbo jZa]jZgbq_gb_f ^hklmiZ GRANT b REVOKE,ZlZd`_g_y\gh_\uiheg_gb_i_j_qbke_gguohi_jZlhjh\q_j_a\u ah\uijhp_^mjbnmgdpbc AZ^Zgb_ 1. Kha^Zlv ljb]]_j dhlhjuc kqblZ_l kj_^gxx klbi_g^bx b \u^Z_l ^bZ]ghklbq_kdh_ khh[s_gb_ ijb ij_\ur_gbb aZ^Zggh]h ihjh]Z mdehg_gby \\h^bfh]h agZq_gby Zljb[mlZ \ aZ\bkbfhklb hl kj_^g_c klbi_g^bbijbwlhfijhbkoh^blaZiheg_gb_g_dhlhjhclZ[ebpu 2. Kha^Zlv ljb]]_j dhlhjuc kqblZ_l kj_^gbc [Zee \ aZ^Zgguc ^_gv b \u^Z_l ^bZ]ghklbq_kdh_ khh[s_gb_ ijb ij_\ur_gbb aZ^Zggh]h ihjh]Z mdehg_gby \\h^bfh]h agZq_gby Zljb[mlZ \ aZ\bkbfhklb hl kj_^g_]h [ZeeZijbwlhfijhbkoh^blaZiheg_gb_g_dhlhjhclZ[ebpu 3. Kha^Zlv ljb]]_j dhlhjuc hij_^_ey_l ]jZgbpu baf_g_gby ghf_jh\ ij_^f_lh\ b \u^Z_l ^bZ]ghklbq_kdh_ khh[s_gb_ ijb ij_\ur_gbb aZ^Zggh]h ihjh]Z mdehg_gby \\h^bfh]h agZq_gby Zljb[mlZ ijb wlhf ijhbkoh^blaZiheg_gb_lZ[ebpu 4. Kha^Zlv ljb]]_j dhlhjuc hij_^_ey_l ]jZgbpu baf_g_gby ghf_jh\ ij_ih^Z\Zl_e_c b \u^Z_l ^bZ]ghklbq_kdh_ khh[s_gb_ ijb ij_\ur_gbb aZ^Zggh]h ihjh]Z mdehg_gby \\h^bfh]h agZq_gby Zljb[mlZ ijb wlhf ijhbkoh^blaZiheg_gb_g_dhlhjhclZ[ebpu 5. Kha^Zlv ljb]]_j dhlhjuc kqblZ_l kj_^gbc j_clbg] mgb\_jkbl_lh\ b \u^Z_l ^bZ]ghklbq_kdh_ khh[s_gb_ ijb ij_\ur_gbb aZ^Zggh]h ihjh]Z mdehg_gby \\h^bfh]h agZq_gby Zljb[mlZ \ aZ\bkbfhklb hl \_ebqbgu kj_^g_]hj_clbg]Zijbwlhfijhbkoh^blaZiheg_gb_g_dhlhjhclZ[ebpu 38
6. Kha^Zlv ljb]]_j dhlhjuc hij_^_ey_l ]jZgbpu baf_g_gby ghf_jh\ e_dlhjh\ \ aZ\bkbfhklb hl ghf_jh\ qblZ_fuo dmjkh\ b \u^Z_l ^bZ]ghklbq_kdh_ khh[s_gb_ ijb ij_\ur_gbb aZ^Zggh]h ihjh]Z mdehg_gby \\h^bfh]h agZq_gby Zljb[mlZ ijb wlhf ijhbkoh^bl aZiheg_gb_g_dhlhjhclZ[ebpu
Ebl_jZlmjZ
1. Bkihevah\Zgb_ORACLEw\b^Hklbg b^j–DFKI[Ba^Zl^hf³
39
6. H]eZ\e_gb_
JZkij_^_e_ggu_[Zau^Zgguo25$&/( ........................................................ 3 KljmdlmjZwda_fieyjh\2UDFOH..................................................................... 3 =eh[ZevgZykbkl_fgZyh[eZklv............................................................... 4 JZa^_ey_fucime.................................................................................. 4 Dwr-[mn_j^Zgguo .................................................................................. 4 ;mn_j`mjgZeZljZgaZdpbc ................................................................. 5 Nhgh\u_ijhp_kku2UDFOH ...................................................................... 5 Ijhp_kku-^bki_lq_ju............................................................................ 6 Ijhp_kkuihevah\Zl_eybk_j\_jZ ......................................................... 7 Hkgh\gu_h[t_dluKM;>25$&/(............................................................ 7 Lbiu^Zgguo25$&/(..................................................................................... 10 Kljhdh\u_lbiu........................................................................................... 10 Qbkeh\u_lbiu ............................................................................................ 10 2.3;blh\u_kljhdb ............................................................................................ 11 Lbiu^ZlZb\j_fy ....................................................................................... 11 L:;EBPU ......................................................................................................... 12 Kha^Zgb_lZebp ......................................................................................... 12 Yaud3/64/...................................................................................................... 14 MIJ:<E?GB?
40