Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
97 views

Developing and Debugging PL&SQL Using Oracle SQL Developer

Developing and Debugging PL&SQL using Oracle SQL Developer

Uploaded by

Leo Chen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
97 views

Developing and Debugging PL&SQL Using Oracle SQL Developer

Developing and Debugging PL&SQL using Oracle SQL Developer

Uploaded by

Leo Chen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 30
5117723, 805 Pa Developing ard Debugging PLISGL using SAL Developer Developing and Debugging PL/SQL using Oracle SQL Developer Purpose This tutorial shows you how to create, run, and debug a PL/SQL procedure using Oracle SQL Developer. Time to Complete Approximately 30 minutes Overview loper is a free graphi and simplifies database development tasks, With Oracle SQL Developer, you can browse database objects, run SQL statements and SQL scripts, and edit and debug PL/SQL statements, You can also run any number of provided reports, as well as create and save your own. This tutorial focuses on creating, compiling, running and debugging PL/SQL. Before starting this tutorial, you should: 1, Install Oracle SQL Developer 3.0 from OTN. Follow the readme instructions here. 2., Install Oracle Database 11g with the Sample schema, 3. Unlock the HR user. Login to SQL. Developer as the SYS user and execute the following commands: alter user hr identified by hr account unloc! grant debug connect session to hr; grant debug any procedure to hr Note: This tutorial is developed using Oracle SQL Developer 3.0. However, you can also use Oracle SQL Developer 2.1.1. 4. Download and unzip the files. C:\sqldev3.0 folder. ip to a local folder on your file system. In this tutorial, we use the Creating a Database Connection hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 130 5117723, 805 Pa The first step to managing database objects using Oracle SQL Developer 3.0 is to create a database connection, Perform the following steps: 1 Ifyou installed the SQL Developer icon on your desktop, click the icon to start your SQL Developer and move to Step 4. If you do not have the icon located on your desktop, perform the following steps to create a shortcut to launch SQL Developer 3.0 directly from your desktop, Open the directory where the SQL Developer 3.0 is located, right-click sqldeveloper.exe (on Windows) or sqldeveloper.sh (on Linux) and select Send to > Desktop (create shortcut). Developing ard Debugging PLISGL using SAL Developer | Gia Fie Folder 11/23/2) Gite File Folder 11/2342 (Gide File Folder 11/2342| Bicev File Folder 11/23/2| Sie File Folder 12)1942| Bivens File Folder 121942 Gib File Folder 11/2342 (Gimodues File Folder 12/1942| (Gores File Folder 112342 (Gskeepyeat File Folder 11/2342 (Gsadevetoper File Folder 11/2342| (Bsai File Folder 11/23/2| tinineFramework Fle Folder 12/1912) Siean.pna 2KB_FNGImage 11/23/2) (Biicev label 1KB. LABEL Fle 11/12/2) E \readne hem 16KB HTMLDocument 11/2842) 32KB. Fpplcaton 11/23/2) [Blsaldeveloper.sh | Open Ke SHFle 11/2342) [lvewsoucepatt Runes: KB US Fle 11/32/2) Sean with FilCure 7p , DP Decrypt file ODP Encrypt fle 1 scan For threats copy CCeate Shortcut Delete Rename Properties 2. On the desktop, you will find an icon named Shortcut to sqldeveloper.exe. Double-click the icon to open SQL Developer 3.0. © Compressed Ginred) Foider © compa [sfosstnearasia | 2 Mal Recipient B my bosuente 2 pv kamprve (&) Note: To rename, select the icon and then press F2 and enter a new name. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 2130 5117123, 805 PM Developing ard Debugging PLISGL using SAL Developer 3. Your Oracle SQL Developer opens, (eee | fle Edt view nevioate Run Versioning Tools Help Gea 07 4880-0 1&! © @aetrase | Ayn. 4. In the Connections tab, right-click Connections and select New Connection. TBiconnections | /renarts rar By Conner ‘Create Lecal Connections 5. The New / Select Database Connection dialog opens. Enter the connection details as follows and click Test. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 30 511723, 805 PM Developing ad Debugging PLISOL using SOL Developer Connection Name: HR_ORCL Username: hr Password: Hostname: localhost Port: 1521 SID: ‘comedienne oR ] Werane i 6. Check for the status of the connection on the left-bottom side (above the Help button). It should read Success. Click Connect. Then click Save. Cereton tne Comectin tae |CeretionNane fA ARCL Hon r@ifocahos:82..| yeomane be ] Sak css =a C3 Ce Ce J Cee eed 7. The connection was saved and you see the newly created connection in the Connections list. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 4830 5117723, 805 PM Developing and Debugging PLISOL using SAL Developer When a connection is created, a SQL Worksheet is opened automatically. The SQL Worksheet allows you to execute SQL against the connection you have opened. Expand the HR_ORCL connection, © [@rec3ca, PESRR BR axa Worksheet Query Buller Creating and Compiling a PL/SQL Procedure In this topic you create, edit, and compile a PL/SQL procedure, Perform the following steps: 1 Right-click Procedures node in the Connections navigator, to invoke the context menu, and select New + Procedure. Bi comectons fel eR ona. Tables [ig tere [3 etioning vens [ig indexes (i aciaes (i routes BB runcors & Bowes [ayo EQ cumies Ta priv rr Sie | [ia comedt lad vee | Conole nal [sequenced Coppel (i rateided Heb (i Matrite d WERETORE 2Enter EMP_LIST as the procedure name and then click “dj to add a parameter. Double-click Parameters name * to allow you to change the value to pMaxRows. Change the type from VARCHAR2 to NUMBER. Click OK. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 5130 5117723, 805 Pat Developing ard Debugging PLISAL using SAL Developer ierpesom ayers tie schemes [im >) None: [ENP_UST (Cd iow Source In omer (Parameters (B00) Name Type Default Value 3 The procedure is created. * Note: At this point, only the shell of the procedure is completed. In the next step, you add more PL/SQL code into the procedure. HR_oRcL | ESIDEPARTMENTS EMP_LIST. ‘Code! Grants | Dependencies |References | Detals |Profles aoe 5g) yb eB CREATE OR REPLACE PROCEDURE EMP_LIST ( ile aR vas ion "mt; 4Replace the following PL/SQL: . BEGIN NULL; END EMP_LIST; ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 6130 5117723, 805 Pa Developing ard Debugging PLISGL using SAL Developer with the following code: (Note: This code is in the file emp_eursor.sq] in the directory where you unzipped the files from the Prerequisites section.) CURSOR emp cursor IS SELECT lvstate province, 1.country_id, d.department_name, e.last_name, j.job_title, e.salary, e.commission pct FROM locations 1, departments d, employees e, jobs j WHERE 1.location_id = d.location_id AND d.department_id = e.department_id AND e.job_id = 37job_id; emp_record emp_cursor$ROWTYPE; TYPE emp_tab_type IS TABLE OF emp_cursorsROW?YPE INDEX BY BINARY_INTEGERs emp_tab @mp_tab_types i NUMBER :- 1; BEGIN OPEN emp_cursor; FETCH emp_cursor INTO emp_record; emp_tab(i) := emp_record; WHILE ((emp_cursor$FOUND) AND (i <= pMaxRows) LOOP iusith FETCH emp_cursor INTO emp_record; emp_tab(i) := emp_record; END LOOP; - CLOSE emp_cursor; FOR j IN REVERSE 1..i LOOP DEMS_OUTPUT.PUT_LINE(emp_tab(j) .last_name) ; END LOOP; END; Notice how the reserved words are formatted by Oracle SQL Developer. To format the code further, right-click within the code editor to invoke the sub menu and select Format. Re cw ey ene By posto ony Selec ll cua, @ Debus chieshif-F10 & compe cure. @ Compiefor Debus ceshine Dan cute preterences. Refactoring > 8 ToLpperhowsertatcan chdcunte ‘Advanced Format, Shi? Quick Outine Popup Descrite shines ‘Open Deciaration Code remalate ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 130 i723, 605 PM Developing and Debugging PLISAL using SOL Developer Compile the PL/SQL subprogram by clicking Save ] in the toolbar. Rees 9 XHH 0-0: &- A connec{ Save (CHT) ©) Gstartrage ire ona._|Goerantments [{] Mp Las7 shy Code) Grants [Dependencies [References [Detaie [Fries EB, connections (Sig(@-erc SR Bf HR ORCL GamsmR emp_cursor 18 Ba Tables SELECT L.state province, L.countey 4d, d.dep i ae cee j.Job_citie, e.salary, e.coumission_p 8 FROM locations 1, departuents a, enployees © Se BInderes went 1 iscacaiod ia + a.iocataon 44 ig Partoces me eae oe eer od ‘Ql Pronedires AND ©. Job_id = j.Job_ias 3B Functions emp_recoré exp_cursorROUTYPE; a sts TWP enp_teb type IS TABLE OF eup_cursorsRow. eup_teb exp_tab_type; DB Trigers mi i 4 NUMBER := 17 BB crecsedtion Tasers aes Bre OPER ij Sextesor? eauenecs FETGH enp_cucsor M0 enp_record; = B a a 2 #2 materialized vews eap_tab(i) i= eup_xecord: e Broce Weg WHILE ((eup_cursoe+FOWND) mW (i <= pllaxRows st Ej synonyms fens if aoe FETCH enp cursor INTO ew record; ag exp_tab(i) i= eup_xecord: 2 ‘@raic Database Lnks in ta: B eo ee CLOSE enp_cursor: a3 “ FOR 3 TW REVERSE 1.4 LOOP Eten ication Express DEMS_OUTPUT. PUT_LINE (emp_tab (3). last_neme mp ran e £2 Gel DE Repostory SCompile errors, if any, are displayed. 6 -{] Procedure HR. EMP _LIST@HR_ORCL (@ Error(20,49): PL5-00103: Encourtered the symbol 'LODP" when expecting cne of the following! --@ err(z2,6):PL5-00103: Encountered the symbal "FETCH" when expecting cne af te folowing @ Erer(25,2):FLS-00109: Encountered the symbol CLOSE" when expecting cre ofthe Fllaning 6By expanding Procedures on the navigator, EMP_LIST can be viewed. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 8130 5117723, 805 PM Developing ard Debugging PLISGL using SAL Developer TA\comeciors tay {A Connections = fa RoR. [Tables «(BQ views | [6 Edtoning Views @- Li Indexes aig Packages 3-G) Process fe] anp_208_HIsToRY @-@ evpist ad Baca «2. Fune(Brocedire HRENELLISTOR TD queue & Quoune Tables (BD Triggers E Ciossediton Triggers (3 la Trees th Gd Sequences Note that when an invalid PL/SQL subprogram is detected by Oracle SQL Developer, the status is indicated with a red X over the icon for the subprogram in the Connections Navigator. 7Compilation errors are shown in the log window. You can navigate to the line reported in the error by simply « double-clicking on the error. Oracle SQL Developer also displays errors and hints in the right hand gutter. If you hover over each of the red bars in the gutter, the error message displays. In this case, the error messages indicate that there is a formatting error in the LOOP statement. After reviewing the code further, you see an extra parenthesis in the WHILE statement. Delete the extra parenthesis. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 9130 5117723, 805 PM Developing ard Debugging PLISAL using SAL Developer Brea gers Code Grants | Dependencies |References |Detais |Profiles ae SDaP-> #ia (UATE OR REPLACE PROCEDURE EMP LIST t pMeskoes 1 NUMER as cunson exp_cursor 1S SELECT 1ostete province, 1.comtry 4d, a.departuent nene, ¢. lest nene, jijob title, e.salery, e.comission pot Fan’iocations tj departacnte:d) exployred’e7 obs: WERE Llocetion td d.location id mmo 4 epactmeat id se depertucne 36 MD #Job. 1a = 3:deb ta; eap_fecord exp_cursov:ROVTVPE: TE exp teb type TS TABLE OF exp cursocMROUTYIE NWEX BY BRR KMTESEI enp_tab enp, tab. type: smi := 1; emt OPEN exp_cursor: ETOH enp.cursor THTO eno_recoré: ee rani ike Sree WHEE ({enp_curseesTOUND) mM (4 x yHaxRows) Lon? 14dp ETOH enp_cursor THO eup_record; eup_tab(i) 1 eup_zecors; HAD Loor; LOSE emp_cursox; FOR } IN REVERSE 1..4 LooP Compiler Log | ®= sect Project: sqldev.tmp:/ideCannections&234R_ORCL jor (5 4] Procedure HR. EMP _LIST@HR_ORCL @ Err01(22,6):PLS-00103: Encounte @ Error(25,3): PL5-00103: Encounter expecting ore ofthe Falawing: —begh F. expecting ore ofthe Falawing: _endnat 8Click Compile. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 10190 5117723, 805 PM Developing ard Debugging PLISAL using SAL Developer Code Grants [Dependencies References [Details [Profiles Cone for Data 23) enp_vab eup_teb_type: zo] 4 NUMER := 1; 23) BEGIN 26) OPEN enp_cursor; 29) FRYGL emp_cursor INYO enp_xecord; 30) enp_vab (2) emp_record; 31) WULE (eup_cuxsorFOUND) AW (i <= pllakRows) ae} Lor 33 iteath: 34 FETCH eup_cursor THTO emp_record; ] 35 emp_vab(i) := emp_record; 36] END Loop; 37) GlOSE eup_carsor; =| 36) FOR 3 IN REVERSE 1. | 3s] Loop . a0) DBNS_OUTPUT.PUT_LINE (emp_tab (3). 1est_name) : ai] EMD Loop; a2) ED; ¥ € > Comper =o ] Projet sade. emo /eConnections23HR_ORCL jr ©] Procecue KR. EMP_LISTIOHR_ORCL 0 EELS Sn @ ferer(2,5) P15-00102: Enccuntred the eymbol FETCH when enpecting one ofthe following: begh Func @ terer(2,2) P1s-cn1c0: Encountered the eymol"CLOSE" when exrecthg aneaf the falawing: end not pra 9The procedure compiled successfully. You are now ready to run the procedure. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 1180 sit723, 605 Pat ‘Dcomnedtions | “aerorts tay EB connectiens fg Hon. Tables (Feed) (5 vews Gi Indexes {ig Packages 3-3) Procedures 4] ADD 168 HsToRY gd] eve ust a 4] SECURE DML 9-8 Functions -£9 Queues A cues Tatles C8 Tages See Tynes GB Sequences L9G tateialned views (5-09 Wateralned views Loge 2-03 Symanyms {Ej Public Synonym: [Gj databace Linke {@] Publ Dstabace Linke 8 @ Drectorins & FE ropleaton Bgr022 ava YL Schemes {Ea 9. Repostory EF cyte in Fo mimrcoe a Note: If you still see a red X over the icon for your procedure under the Procedures node, Developing ard Debugging PLISGL using SAL Developer OC) Byee_cea |) ewpsuast.| Code Grants [Genendencis [References [Detalc[PreFles Za a] crear on rerLace 2| Gl ymocepune ENP_LIST( a PHHOKOVS HAMNER | De bw | 3] anc exe sunset 1) smner 1.seace province, al a.departuent_neme, il) seem, hb) matte, ial FROM locations 1, | er i] wn ew. cape zs ‘lick the refresh icon. ‘A green overlay indicates the procedure has been compiled for debugging. No additional overlay means the procedure has been compiled without additional debugging directives. Th ese are controlled by preference settings and the compile droplist option. The default in SQL Developer is "Compile for Debug" Running a PL/SQL Procedure Onc the following steps: ce you have created and compiled a PL/SQL procedure, you can run it using Oracle SQL Developer. Perform 1. Right-click on EMP_LIST in the Connections navigator and select Run. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 1200 5117723, 805 Pa ar EB connections Gf Ror. (GBA Tables (tered) Ba vews {i Indexes Lig Packaoes E-GD) Procedures 4] 400.303 HISTORY yen. code| Grarte [Dor (Brepors Developing ard Debugging PLISAL using SAL Developer 5B Finca ootug euteenitFa0 . co @ compile cunre Ene a conecortebog cvsinte BR Tes GB Sea LB Mater LB Mater Gran. LB Smon neve (LGM Pubes prop (Ai Datab| —Conpile Dependents fad Public ouch oo , GB dre iad FF focicdemt 2.. This invokes the Run PL/SQL dialog. The Run PL/SQL. dialog allows you to select the target procedure or function to run (useful for packages) and displays a list of parameters for the selected target. In the PL/SQL block text area, you will see the generated code that Oracle SQL Developer uses to call the selected program. You can use this area to populate parameters to be passed to the program unit and to handle complex return types. In your EMP_LIST procedure, you have a parameter named PMAXROWS. In the Run PL/SQL dialog, you can initialize that parameter to any number value. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 19190 5117123, 805 PM Developing ard Debugging PLISAL using SAL Developer tse LBed pect © mumnous numbers bent OWS = HLL: EMP_LIST( Change PMAXROWS 5; Then click OK. NULL; to PMAKROWS ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 5117723, 805 Pa Developing ard Debugging PLISAL using SAL Developer Sets ic) est Eames = baat eke] Pinos cc SQL Bok DECLARE PHAXROVS number; BESDI Paaxmous := sh EMP_LIST( HIXROVS => PERO oe < > ieveFie.. | HonFie.. | Bent] (og) [cancel Pe 3. The results are displayed in the Running - Log window. Running: IdeConnections%23HR_ORCLipr - Loa (eo 4) Connecting to the database HE_ORCL Por creenberg King Process exited. Discomecting from the databese HE_ORCL. Debugging a PL/SQL Procedure Oracle SQL Developer also supports PL/SQL debugging with Oracle databases. In this topic, you debug a PL/SQL Procedure, step through the code and modify a value at runtime. Perform the following steps: ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 19190 5117723, 805 Pa Developing ard Debugging PLISGL using SAL Developer 1. To assist with debugging, line numbers can be added to the Code window. Right-click on the margin and select Toggle Line Numbers. ‘Code Grents [Dependencies [References [Details [Profiles ae LDP DoH Se TE t ic ie Sayan ToggleBoolmark —cttK ToggleBreskpoint Fe Disable Quek Dit Set Dif Reference = 0 eup_record; eup_tab(1) := eup_record; WHOLE (emp_cursor#FouND) amp (1 <= pMacRows Lisaeds FETCH eup_cucsor TWO emp _record; femp_vab(1) END LOOF; eup_recora; CLOSE eup_cursoc; 2. To debug a procedure, you need to Compile for Debug first. This step adds in the compiler directives required for debugging. Once you have completed the debug, you should compile the procedure again and remove the extra directives. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 16190 5117723, 805 Pat Developing ard Debugging PLISAL using SAL Developer Dama [jews Code) Grants [Gependencis [References [Getals [Profies create oF replace qe ‘PROCEDURE EMP_LIST @ connie 3. A breakpoint is a location in the code that you identify as a stopping point. When code is run in 5 a pllexRous IN NUMBER ) as ‘cuRSUR enp_cursor 1S SELECT 1.state province, 1.cemery_id, d.departuent j-job_title, e,selary, e.ccmission pot FROM locations 1, departments d, employees ¢, jobs WERE 1.locetion id = d.location id AND 4. departwent_ad = e.departuent_id BND 2.j0b_id = 3.30b_ids enp_record emp_cursorsROWT?PE; TYPE enp_tab_type IS TAHLE OF enp_cursor®ROWIYPE IN eup_tab eup_tab_type: i MUMGER := 1) BEGIN omen enp_cursor; FETOK emp_cursor THO exp_cecord; eup_tab(i) := eup_recorés WEEE Jenp_cursor#FOUD) 3D (4 dinitl FETOK enp_cursor TATO enp_record; eap_tab(i) r= emp record; END LOOP; LOSE enp cursor; FOR j IN REVERSE 1..4 Loo? DBNS_OUTYUT. PUT LIME emp_tab(3}. lastname) ; END LOOP; =D; pllaxRows) LOOP debug mode, execution will stop at the breakpoint. Set a breakpoint in the symbol. Then click the Debug icon. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him EMP_LIST procedure by clicking in the margin at the line with the OPEN emp_cursor; statement. The line number is replaced with a red dot. This is a breakpoint 7180 5117723, 805 Pa Developing ard Debugging PLISAL using SAL Developer Code) Grants [Dependencies [Referendes [Dela [Profiles BZ @ece = aa 1) Seam on mePLAGE PHOCEDUME ENP LIST aye g]* puserous a mune yas s| CURSOR enp_cursor IS "ster Ioseatepevvince, Iocouey $4, dakpertn : ji gob_ tele, ecselaty, e.coimdssion, pet a] mm soretions 1, departaents dy eaplayess ey debs a] WERE 1. locecin id" a location ta io] MD dudapectnest id ¢ ecaepertnent i Li) ap ectabid = 3-job_46s Xe) ew_secord em curser OUTTE; 16) THRE cap tab type 18 TAILD OF enp_cursovSROVIVDE Z 4 eup_teb exp_tab_ tye; rl ie | om pas le) EEteN exp cucser TO emp record; 1e||| tans tabtti i en, reesees 20) WOKE (em carecSFOND) MD (<= tows) tor a) assis 22) ERTOt eap.cursor Tino enp_seeor ze] | _eapscabii) = ew. record 4. The Debug PL/SQL dialog should still show the value PMAXROWS = 5; Click OK. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 18190 5117123, 805 PM Developing ard Debugging PLISAL using SAL Developer USL BIO fprciare 2] puoqoUs mumer; 3 oem FmRoUs ENP_LIST( POROUS => HARON 5. Click Log tab, if it is not already displayed. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 511723, 805 PM Developing and Debugging PLISOL using SOL Developer ao Tee eer tar (et enc etree lal te + excononas $ Bhooatms 3 Geeocans Ponons, 2 Booster F Bacees aos Timoeiers ‘SECT Lotte peevnce, L.ceintey_1y éadepartaent nae, ¢Le sane, Piaease some Counseiea pet 2 Gaye eevee a Sid 6.. The debugger should halt at the line where you placed the breakpoint. You can now control the flow of execution, modify values of variables and perform other debugging functions. Click Step Into @- ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 20830 5117723, 805 Pa Developing ard Debugging PLISAL using SL Developer Gyecoa (Q)em ust code Grants [Cependencies [References [Dota [profes Bea: aD)e p> #ia 4 (CREATE OR REPLACE FROCEDURE EMP_LIST a iG 4) eee ae ol | mumeaccecions 1, epertacats d, employtes ¢, 30bs5 : WERE 1. locetion id = d.location id 15) Ty cup eat eye TS TOBLE OF eap_cursorSROMIYPE TEX BY BGR _TATEGER: 1a] | | empiieen exp! Gah type | 0% ombay ease ee iol || reset esp-aursee Tap exe recs? ial} gayest ean eeeape 20, WOE (emp_cursorsFOUND) AND (i ail iieaitd: zal FETOE emp_cursor INTO enp_record; eup_tab(i) := emp_record; pllaxRovs) LOOP Connecting to the databese HR_ORCL Executing PL/SQL: ALTER SESSION SIT PLSQL D4! Hzecuting PL/SQL: CALL BMS DEBUG_SDUP.COMMECT_TCP( '127.0.0.1', '3859" ) Debugger accepted conection from database on port 9869 Source breakpoint occarred at line 17 of HM? LIST pls ‘Note: You have been granted the DEBUG CONNECT SESSION and DEBUG ANY PROCEDURE user privileges in the Prerequisites section to avoid the following error message when debugging. [boebussra-.25 | Conneccang co the database HR_ORCL Eeecubing Fo/sQh: abTER sieeron eet PLegi_vEBUGATHUE Rromvting PL/SQ1: CALL 9RMS_ORRUG_TOWE.cOMMRCT_SeD( 1127.0.0.1', 14127" 9 ORA-01091: incusfieient priviledes ORA-06512: at “SYS.DEMS_DEBUC_IDUP", line 68 ORA-06512: at Line 1 This session requires DEBUG COUNECT SESSION and DEBUG ANY PROCEDURE ucer privileges Messages [Detaeator |D>runing | i@tbenuong | io ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 2130 5117723, 805 Pa Developing ard Debugging PLISGL using SAL Developer 7. This takes you to the first line of the cursor, Click Step Into q again, Geen Code Grants | Dependencies [References | Detals |Profiles: eva 00), un 1] @cxeans OR REPLACE PROCEDURE EMP_LIST 4 | oe a) as Ue cnttiicag. ream | epgestesed cae ocoemneetteeemeee te fetes meemeneteenee fuente ener : a inant eae eigtiarypiejceaaieeton poe WD emmesoars ase wena aaah cr ecteaesy © tone 4 4|| | teem. lscueion va + &-locaeion 4a lB am aceepacenet stale eae jareaene 00 Li] am e.jeb.te'= 3-3eb 10s 12] | eap-record enp_oursoZ*RIVTTPE: 13) THPE emp cab type 18 TAME UP exp_cursorSROVIYPE LDEX BY uiNaRY_EGER; 1a IE engin ipl ethlcpe ts] {x ammge t= 17 ts] scom o| aieeemeree | wero expcursor MNO ep records to|[g. espiean(t) snean-tecoras 20] wae (enp_cursorSFOUND) AMD (4 <= pMoxovs) LOOE | arrests 22|(frerat eap:qucaor HTD exp:xerond AIM eapscanl | swieperesores Dehugaing: IdeConnections¢423HR_CRCL.jpr~L 3oa*€ Connecting to the database HA_ORCL Executing PL/SQL: ALTER SESSION SIT PLSQI_DsBUC Executing PL/SQL: CALL DBMS DEEUG_JDUP.CCNNSCT_TCP( "127.0.0.1", ‘3804! ) Debugger accepted comection trom database on port 9604 Source breskpeinc occurred av line 17 of SMP_LIST.pis. 8. You should now be selecting the first row of the cursor. Click Step Into q 3 more times. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 2230 5117723, 805 PM Developing ard Debugging PLISAL using SAL Developer Syrecect [Zeist | Cade Grants [Dependencies (References IDetals [Profiles eb eR 1) CREATE OR REPLAGE PROCEDURE EMP_LIST a 3) pllexRows 1H mere a) yas 5) CURSOR enp_cucser IS > 1 j-job_title, e.salery, e.commission pct 8) FROM locations 1, departments 4, eupleyers e, Jobs 3 : WERE 1, location id = 4. location aa 10 iD ds deparcaent id = e, departuent_id Lili mw coonaa © jee, 12) exp record enp_carsorsROVTv?E; IPE enp_tab_type IS THBLE OF emp_curcor+ROWIYPE TNDEX BY BINRRY_INTESER; 14) exp_tab eup_teb_tvpe: 1s) i mnie 16| Brom ovr enp_eueaors 18) FFTCE aup_eursor THTO ep_record? cesta te roo 2)5) WO jew_snoceSTOOD) mM (i < pease) Loon bial al FETGE eup_cursor INTO eap_eecord: 20) renee |i) 1s expressed) @ OS Connectang co the database HR_ORCL Executing PL/SQL: ALTER SESSIOU s#T PLEOL_D Hxecucing PL/SQL: CALL 9BMS_DH5UG_foWE.COMMRCT_rC¥( “1z7.0.0.1', *9869" ) Debugger accepted comectzon trou database on port 3363 Source breakpoine oceurred ao Line 17 of HNP_UEST.pls 9. Select Data from the tab above. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 2830 5117723, 805 PM Developing ard Debugging PLISAL using SAL Developer Gsarcas [@peona. jew ast ‘Code Grants [Dependencies [References |Detals [Profiles UF “> eR a| create or replace 2) B PROGSDURE EMP_LIST 4) pllaxRows IN NUMBER s| ) as 6] CURSOR enp_cursor IS 4| a SELECT L.state province, 1.country_id, d.departuent name, e.last_nexe, jejob_title, e.salery, e.comission pez 3} FROM locations 1, departments 6, employees e, jobs 3 10) WERE 1. location dd = d.location id 11) WD a.department_id = e.departuent_id 12) AND e.30b_id = 4. 3eb_id; 13) eup_record emp_cursor+ROWIYPE; 14) TPE enp_cab_type IS TABLE OF enp_cursor+ROWTYPE INDEX BY BINARY_INTEGER 15) eup_cab eup_tab_type; 16] i NUMBER == 1; 15] prem @| OPER enp_cursor; 18) FETOH ewp_cursor INTO enp_xecord; 23) FETA eup_cursor NTO ewp_record; 24) eup_tab (2) := eup_record; 25| | END LOOP; 26 CLOSE emp cursor; Connecting to the database HR_ORCL Executing PL/SQL: ALTER SESSION SET PLSQL_DEBUGATRUE Executing PL/SQL: CALL DBMS DEBUG_SDUP.COMNECT_ICP( '127.0.0.1", '2782' } Debugger accepted conection from database on port 2752. Source breakpein: occurred at line 18 of EMP_LIST ple 10 . The Data window starts to show a limited list of variables which are used in the line of code that is about to be executed, and in the previously executed lines, ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 2430 siv7as, 805 PM Developing and Debugging PISA. sing SOL Developer Acemnactens Cy) Dakar Face (ARON |S] EnPLIsT | |\+ aT |= |B conrectins EB HR ORCL a -( Tabes | Bens 3B Ectoning ens Ga indexes (i Paclages (3-3) Procedwes rts [Dependencies [Referancos [Detail [Profi | eee [Pte eect, count, emie i FROM locations 1, departuents 4, employees e, 3c ef] aoe toetiste |) 1) a a.ceparemeny_ia = e-ceparcuene, ta ec BL ECL OM 13) emp_record eup_curso1=ROW™! Lene 1a) TWRH eap_tab eye 15 TALE oF eap_curcocsnovrrn: onek is] | emp_cap enp_can_cvper nen 17) ent [Ey HR.ANONYMOUS_BLOCK Al CES ere 19) BETH emp_cursor Dro ewp_cecord; eup_veb (1) : Name Value Type i pmexrows 5 NUMBER El ENP RECoRD Fowtyne o EL EMP TAs indexedtable —EMP_TAB_TYPE Ai 1 NUMBER 11. Right-click the line that reads DBMS_OUTPUT.. PUT_LINE(emp_tab(j) .last_name) ; and select Run to Cursor. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 28130 5117723, 805 PM Developing ard Debugging PLISAL using SAL Developer Daareace _[ByR_onc. Code) Grants [Dependendes [References |Detals [Profiles Nome Gl pmasrows 5 mo © a Bl evr reconp Fe © Gl ew ras indexed tal ch Gr 1 cursor enp_cursox IS SELECT luetate_province, 1. country id, d.departuent_nane, e.last neue, Jejoo_title, e.salery, e.comicaion pot FROM Locations 1, dayartments d, empleyees e, joba 3 WERE 1. location dd ~ d, location ad TMD a. departuent id - e.departnent_id BUD ¢.job_id = 3.job_ids eup_record emp_carsor*ROWTYTE; PE exp_tob_type IS TABLE OF enp_curcor‘ROWIYPE INDEX BY BINARY_INTEGER, eup_vab emp_tab_types i MMMOER 3 1; oa ee Eonar ime 2) AGEE (exp cursorsromm) mb (2 ee pRowRows) UO Be enpecesoontin ap recat Stes eee, mea fa te eee cous BMS, HUPUT. POTN (expt (3) 1898 pane) 2 ‘EMD LOOP; eee Ca 12. Expand EMP_TAB >_ values > [1] > _value. You sce the values of the fields in a given record of the table, Select the LAST_NAME field. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 26830 5117723, 805 PM Developing ard Debugging PLISAL using SAL Developer Dstrteage — [Gswe_orc |) eme_ust ‘Code Grants |Dependencies {References | Details |Frofles at BE SDP Pe (Biocs* ua] | mw e:gop_a€ 3.30040; 23] | eup_tecor’ eap_cursczMRovrmre; 24] | Tape exp, cap type 15 TABLE OF emp_cursor¥ROWTYPE MEX BY Bm a) Sees 1] eam ©) oven emp cursor? rn as] | EETCW enp cursor INTO exp_record; 20] | exp_tab(a] t= enp_cecora; 2i|(8) wie (enp_cursor¥FUUND) AND (4 ¢* pMexBous) LOOP 2 Weed 2 FETOI enp_Gursor INTO enp_secord: 2al enp_teb(i) '= enp_record: 23| | ew Loop; 26| | close enp cursor: 21] Fon 3 IW REMERSE 1.4 LooP 2 a 23] Ew Loop: 20] ED; ke > buna: Heron... _|@Strealarts [[esmat oats [tlibata e]Watches Nene eb r= @-O _vabe Rowtype (] COMMISSION. PCT NULL NUMBER(Z,2) © country ‘us CHAR(Z) (fQ] DEPARTMENT_NAME ‘Executive’ VARCHARZ(30) ©) 308_tme. ‘President’ WARCHARZ(35) satay 24000) NUMEER(,2) ‘ofE] STATE_PROVINCE — “Washington’ VARCHARZ(25) sO EMP_TAE_TYPE element Bey 2 PLS_INTEGER 13 . Right-click the LAST_NAME field and select Modify Value hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 21630 5117723, 805 PM Developing ard Debugging PLISAL using SAL Developer TeWwacies Debusging: HeConn... |= Brealpoints [sratoats [Data Name value Type ° &-O EMP_Tag indexed table -EMP_TAB_TYPE r co) BG vahes EM_TAB_TYPE element] ° 2Onl EMP_TAB_TYPE element Bey 1 PLS_INTEGER, ° &-O _vate Rowtype EA commssion_pcT NULL. MUNBER(2,2) Gl country_10 ws CHAR(2) - EUDEPARTMENT_NAME ‘Executive’ YARCHARZ(30} 1 308_tme ‘President’ ARCHARZ(35) salary as © ESTATE PROVINCE ‘Wastinay —‘Hateh . eau Inspect Bie 2 ‘Walch Cass Loader ° o-E vate Inspect Cless Loader Ss geo ‘Object Preferences. . #on Y ° #OB Export . sn Preferences A olepse al 60 to Source For Rowlype, LAST_NAME 14. Change the name to another value, such as James, and click OK. © Modify value YaRCHARS LAST_MAME ‘Current Value: Danes [Clinterpat Now Vako ar Objct Adiroee 15 . Select the Debugging - Log tab. ntps:iwwww oracle.com/webfolderechnetwork/utorialsobeldbisqldevir30plsal_debug_OBE/plsq| debug_otn. htm 2030 5117723, 805 PM Developing and Debugging PLISOL using SAL Developer eakcoints |SeSmert Gata |[eData | llGlWatches ebucaer ating Nane We Value Type © El ere_tas Indexed table ENP_TAB_TPE fr © Sl yates ENP_TAB_TYPE element{e] ° eOn EMP_TAB_TYPE element Gl key 1 PL5_INTESER ° Rowtype Gl commission_PcT NULL NUMBER(2,2) Bi county us Harz) (E] DePARTMENT_NANE ‘Executive’ ver cHaRa(s0) G10 me President aRcHARa(s5) Co SALARY 24000, NUMBER(8,2) [EU STATE PROVINCE "Weshington’ —_VARCHAK2(Z5) . sO EMP_TAB_TYPE element Gl key 2 PLS_INTEGER ° e- value Rowtype ° eB ENP_TAB_TYPE element ° eB ENP_TAB_TYPE element . eOel ENP_TAB_TYPE element ° eS ENP_TAB_TYPE element -al 6 NUMEER Qs 6 PLS_INTEGER Note that you have changed the value of the variable at run time. This is very helpful in debugging code, 16 .Click Resume [jp to allow the PL/SQL to run to completion, @Ztredpcnts igbsnat ate [idibata (watches ie Connecting to the database HA_ORCL = Executing PL/SQL: ALTER SESSION S87 PLSQ)_DEBUGHTIUE Executing PL/SQL: CALL DBMS DREUG_JDUP.COMNECT_ICP( '127.0.0.1", "4188" ) Debugger accepted comection from databare on port 41¢8 Source breakpcint occurred at line 18 of EMP_LIST.pls. 17 . Check to see that your modified value is displayed in the Log window. hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 20830 5117723, 805 PM Developing ard Debugging PLISGL using SAL Developer icy Bo Connecting to the databace HROICL, Executing PL/SQL: ALTER SESSION SET PLSQL_DESUCHTRUE Bxecutang PL/SUL? CALL DSHS_DEBUG_sDUP.CONNACT_TCP( “127-0.0.1 Debugger accepred connection trom dacabase on por 2206 Z08" Euaeweing PL/SQL: CALL DeMS_DEBUC_IDUP.DrscoMMECT() Greenberg Whalen Kechhar De Haan Jame Process exited, Disconnecting from the database HR_OICL Debuyger disconnected from dazabasa. Summary In this tutorial, you have learned how to: + Create a Database Connection Browse the Database Create and Compile a PL/SQL Procedure Run a PL/SQL Procedure Debug a PL/SQL Procedure : « snwi About Oracle |Oracle and Sun || Careers | Contact Us ton “ scans Sollware taeinceres to Work ‘Site Maps | Legal Notices | Terms of Use | Your Privacy Rights hitps www oracle. comobfoldertechnetworktutorials/obeldbisqldevr3Oiplsql_debug_OBEIplsql debug otn him 30030

You might also like