• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
IBM DB2 10
 

IBM DB2 10

on

  • 337 views

 

Statistics

Views

Total Views
337
Views on SlideShare
337
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    IBM DB2 10 IBM DB2 10 Document Transcript

    • 0DB2 DatabaseBySunny Okoro
    • 1ContentsDatabase Platform................................................................................................................................................................... 3Applications............................................................................................................................................................................... 3Sample Database Installation............................................................................................................................................. 7Built In Function..................................................................................................................................................................11User Defined Function.........................................................................................................................................................13Data Definition........................................................................................................................................................................16Stored Procedures.................................................................................................................................................................18Triggers......................................................................................................................................................................................21
    • 2
    • 3Database PlatformIBM DB2EXPRESS EDITIONApplicationsDB2 Command Line Processor
    • 4Microsoft Visual Studio 2010 and 2012Oracle JDeveloper
    • 5IBM Data StudioMicrosoft Visio 2010
    • 6Microsoft Excel and Power Pivot
    • 7Sample Database Installation
    • 8
    • 9
    • 10
    • 11Built In FunctionColumn functionsSELECTC.CUST_LAST_NAME ,C.CUST_FIRST_NAME,C.CUST_CODE, C.CUST_AGE, C.CUST_CITY,C.CUST_PROV_STATE, CON.ISO_THREE_LETTER_CODE,CON.COUNTRY_EN, SUM(COH.CUST_TOTAL)as Cust_Total,Max(COH.CUST_TOTAL)as Highest_Cust_Total,Min(COH.CUST_TOTAL)as Lowest_Cust_TotalFROMGOSALESCT.CUST_ORDER_HEADER COHINNER JOINGOSALESCT.CUST_CUSTOMER CONCOH.CUST_CODE = C.CUST_CODEINNER JOINGOSALESCT.CUST_COUNTRY CONONCON.COUNTRY_CODE = C.CUST_COUNTRY_CODEGROUP BY C.CUST_LAST_NAME, C.CUST_FIRST_NAME, C.CUST_CODE, C.CUST_AGE, C.CUST_CITY, C.CUST_PROV_STATE, CON.ISO_THREE_LETTER_CODE, CON.COUNTRY_ENCUST_LAST_NAME CUST_FIRST_NAME CUST_CODE CUST_AGE CUST_CITY CUST_PROV_STATE ISO_THREE_LETTER_CODE COUNTRY_EN CUST_TOTAL HIGHEST_CUST_TOTAL LOWEST_CUST_TOTALKennedy Debbie 100136 19 Brisbane Queensland AUS Australia 174.57 98.7 75.87Stedman Helen 100359 25 Brisbane Queensland AUS Australia 907.34 519.73 387.61Durán Grenadda 100656 33 Brisbane Queensland AUS Australia 1072.18 959.14 113.04Salter Zinia 100732 45 Brisbane Queensland AUS Australia 384.75 220.52 164.23Merriman Rodney 100844 31 Brisbane Queensland AUS Australia 869.04 621.61 247.43Jensen Vivian 100967 29 Brisbane Queensland AUS Australia 590.54 299.93 290.61Harriman Trent 101003 19 Brisbane Queensland AUS Australia 1390.99 1321.38 69.61Rolson Ivan 101103 27 Brisbane Queensland AUS Australia 729.15 464.4 264.75Results AbridgedScalar functionSELECTC.CUST_LAST_NAME ,C.CUST_FIRST_NAME,C.CUST_CODE, C.CUST_AGE, C.CUST_CITY,C.CUST_PROV_STATE, CON.ISO_THREE_LETTER_CODE,CON.COUNTRY_EN,COH.CUST_ORDER_DATE,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,YYYY-MM-DD)AS CUST_ORDER_DATE2,date (COH.CUST_ORDER_DATE) as DATE,month (COH.CUST_ORDER_DATE) as MONTH,day (COH.CUST_ORDER_DATE) as DAY,DAYOFWEEK_ISO (COH.CUST_ORDER_DATE) as WEEK,year (COH.CUST_ORDER_DATE) as YEAR,time(COH.CUST_ORDER_DATE)as TIME,hour(COH.CUST_ORDER_DATE) as HOUR,quarter(COH.CUST_ORDER_DATE) as QUARTERFROMGOSALESCT.CUST_ORDER_HEADER COHINNER JOINGOSALESCT.CUST_CUSTOMER CONCOH.CUST_CODE = C.CUST_CODEINNER JOINGOSALESCT.CUST_COUNTRY CONONCON.COUNTRY_CODE = C.CUST_COUNTRY_CODEGROUP BY C.CUST_LAST_NAME, C.CUST_FIRST_NAME, C.CUST_CODE, C.CUST_AGE, C.CUST_CITY, C.CUST_PROV_STATE, CON.ISO_THREE_LETTER_CODE, CON.COUNTRY_EN,COH.CUST_ORDER_DATECUST_LAST_NAME CUST_FIRST_NAME CUST_CODE CUST_AGE CUST_CITY CUST_PROV_STATE ISO_THREE_LETTER_CODE COUNTRY_EN CUST_ORDER_DATE CUST_ORDER_DATE2 DATE MONTH DAY WEEK YEAR HOUR QUARTERAraújo Juliana Sofia 100025 23 Osasco São Paulo BRA Brazil 1/25/2004 8:15 1/25/2004 1/25/2004 1 25 7 2004 8 1TaveresIfran Ranulfo 100050 43 Rio de Janeiro Rio de Janeiro BRA Brazil 1/8/2004 16:31 1/8/2004 1/8/2004 1 8 4 2004 16 1CrépisTelles Bruno Miló 100082 30 Paranaguá Paraná BRA Brazil 1/10/2004 10:10 1/10/2004 1/10/2004 1 10 6 2004 10 1Sávia Edu 100097 28 Porto Alegre Rio Grande do Sul BRA Brazil 1/17/2004 18:08 1/17/2004 1/17/2004 1 17 6 2004 18 1Fontes Filipo 100113 44 Navegantes Santa Catarina BRA Brazil 1/21/2004 9:08 1/21/2004 1/21/2004 1 21 3 2004 9 1Vila Rangel Zizi 100117 42 Salvador Bahia BRA Brazil 1/30/2004 22:52 1/30/2004 1/30/2004 1 30 5 2004 22 1Cabuçu Stefania 100120 29 Timóteo Minas Gerais BRA Brazil 1/3/2004 8:33 1/3/2004 1/3/2004 1 3 6 2004 8 1da Gamboa SandroReinaldo 100141 26 Navegantes Santa Catarina BRA Brazil 1/1/2004 16:59 1/1/2004 1/1/2004 1 1 4 2004 16 1Moreira da Estrela Fernanda 100169 24 Porto Alegre Rio Grande do Sul BRA Brazil 1/1/2004 20:15 1/1/2004 1/1/2004 1 1 4 2004 20 1Arapuã Ricardo 100232 34 Rio de Janeiro Rio de Janeiro BRA Brazil 1/10/2004 18:02 1/10/2004 1/10/2004 1 10 6 2004 18 1Result AbridgedSELECTUPPER (C.CUST_LAST_NAME)AS CUST_LAST_NAME , LOWER (C.CUST_FIRST_NAME) AS CUST_FIRST_NAME,C.CUST_CODE, C.CUST_AGE,C.CUST_CITY CONCAT,CONCATC.CUST_PROV_STATE CONCAT,CONCAT CON.COUNTRY_EN AS CUST_LOCATION,
    • 12COH.CUST_ORDER_DATE,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,YYYY-MM-DD)AS CUST_ORDER_DATE2,date (COH.CUST_ORDER_DATE) asDATE,month (COH.CUST_ORDER_DATE) asMONTH,day (COH.CUST_ORDER_DATE) asDAY,DAYOFWEEK_ISO (COH.CUST_ORDER_DATE) asWEEK,year (COH.CUST_ORDER_DATE) asYEAR,time(COH.CUST_ORDER_DATE)asTIME,hour(COH.CUST_ORDER_DATE) asHOUR,quarter(COH.CUST_ORDER_DATE) asQUARTER,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)AS CUST_ORDER_DATE3FROMGOSALESCT.CUST_ORDER_HEADER COHINNERJOINGOSALESCT.CUST_CUSTOMER CONCOH.CUST_CODE =C.CUST_CODEINNERJOINGOSALESCT.CUST_COUNTRY CONONCON.COUNTRY_CODE = C.CUST_COUNTRY_CODEWHEREC.CUST_CITY CONCAT,CONCATC.CUST_PROV_STATE CONCAT,CONCAT CON.COUNTRY_EN ISNOTNULLGROUPBYC.CUST_LAST_NAME, C.CUST_FIRST_NAME, C.CUST_CODE, C.CUST_AGE, C.CUST_CITY, C.CUST_PROV_STATE, CON.ISO_THREE_LETTER_CODE, CON.COUNTRY_EN,COH.CUST_ORDER_DATEResult AbridgedCUST_LAST_NAME CUST_FIRST_NAME CUST_CODE CUST_AGE CUST_LOCATION CUST_ORDER_DATE CUST_ORDER_DATE2 DATE MONTH DAY WEEK YEAR HOUR QUARTER CUST_ORDER_DATE3RYAN mat 118394 17 Anchorage,Alaska,United States 3/2/2006 16:12 3/2/2006 3/2/2006 3 2 4 2006 16 1 Thursday-02-March-2006EISEN ernst 106515 17 Apeldoorn,Gelderland,Netherlands 11/15/2007 15:04 11/15/2007 11/15/2007 11 15 4 2007 15 4 Thursday-15-November-2007EISEN ernst 106515 17 Apeldoorn,Gelderland,Netherlands 11/24/2004 4:23 11/24/2004 11/24/2004 11 24 3 2004 4 4 Wednesday-24-November-2004MIKHAILOV georgiy 130664 17 Astrakhan,AstrakhanOblast,Russia 4/30/2007 16:25 4/30/2007 4/30/2007 4 30 1 2007 16 2 Monday-30-April-2007KRIEGER holger 126830 17 Augsburg,Bavaria,Germany 11/26/2006 6:18 11/26/2006 11/26/2006 11 26 7 2006 6 4 Sunday-26-November-2006GONA kelmojabuti 125044 17 BalneárioCamboriú,SantaCatarina,Brazil 9/1/2006 18:28 9/1/2006 9/1/2006 9 1 5 2006 18 3 Friday-01-September-2006BÄCKER karsten 127161 17 Bern,Bern,Switzerland 12/13/2006 0:05 12/13/2006 12/13/2006 12 13 3 2006 0 4 Wednesday-13-December-2006
    • 13User Defined Functioncreate function GOSALESCT.CUST_AGE(CUSTCODE INTEGER)RETURNS INTEGERNOT DETERMINISTICLANGUAGE SQLCALLED ON NULL INPUTRETURN SELECT CUST_AGE FROM GOSALESCT.CUST_CUSTOMER WHERE CUST_CODE = CUSTCODESELECT CUST_CODE, CUST_FIRST_NAME, CUST_LAST_NAME,CUST_AGE(CUST_CODE) AS CUST_AGEFROM GOSALESCT.CUST_CUSTOMERWHERE CUST_CODE = CUST_CODECUST_CODE CUST_FIRST_NAME CUST_LAST_NAME CUST_AGE--------- ---------------- -------------------- --------126887 Victor Hernández 31119428 Cuilan Dong 60119433 TaisiaLadislavova 22119434 Jianhua Pang 42119469 Edward Afinogenov 52Result Abridgedcreate function GOSALESCT.CUST_NAME(CUSTCODE INTEGER)RETURNS VARCHAR(200)NOT DETERMINISTICLANGUAGE SQLCALLED ON NULL INPUTRETURN SELECT CUST_FIRST_NAME CONCAT , CONCAT CUST_LAST_NAME FROM GOSALESCT.CUST_CUSTOMER WHERE CUST_CODE = CUSTCODESELECTCOH.CUST_CODE , CUST_NAME(CUST_CODE)AS CUST_NAME,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)AS CUST_ORDER_DATE,COH.CUST_ORDER_NUMBER, COH.CUST_TOTAL, COH.CUST_SALES_TAX,COH.CUST_TOTAL_QUANTITY,PNL.PRODUCT_NAMEFROMGOSALESCT.CUST_ORDER_HEADER COHINNERJOINGOSALESCT.CUST_ORDER_DETAIL CODONCOH.CUST_ORDER_NUMBER = COD.CUST_ORDER_NUMBERINNERJOINGOSALES.PRODUCT_NAME_LOOKUP PNLONPNL.PRODUCT_NUMBER = COD.PRODUCT_NUMBERWHERE CUST_CODE = CUST_CODEAND PNL.PRODUCT_LANGUAGE =ENCUST_CODE CUST_NAME CUST_ORDER_DATE CUST_ORDER_NUMBER CUST_TOTAL CUST_SALES_TAX CUST_TOTAL_QUANTITY PRODUCT_NAME--------- -------------------------------------- --------------------------- ----------------- ---------- -------------- ------------------- ---------------------------------118250 Gil,Conselheiro Friday-31-March-2006 147965 881.74 166.33 2 Hibernator Lite118862 Annett,Jaeger Saturday-29-April-2006 149549 165.44 22.82 1 Venue120229 Gang,Dong Thursday-20-April-2006 153087 934.44 44.50 4 Canyon Mule Carryall120229 Gang,Dong Thursday-20-April-2006 153087 934.44 44.50 4 Hibernator120690 James,Morton Sunday-28-May-2006 154275 163.37 21.31 2 TrailChef Single Flame120690 James,Morton Sunday-28-May-2006 154275 163.37 21.31 2 TrailChef Kitchen Kit123917 Elena,Bolton Saturday-22-July-2006 162633 300.24 41.41 1 Opera Vision126480 Charles,Lanford Thursday-23-November-2006 169300 25.53 2.32 1 Single EdgeResult Abridged
    • 14SELECTCOH.CUST_CODE , CUST_NAME(CUST_CODE)AS CUST_NAME,CUST_AGE(CUST_CODE)AS CUST_AGE,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)AS CUST_ORDER_DATE,COH.CUST_ORDER_NUMBER, COH.CUST_TOTAL, COH.CUST_SALES_TAX,COH.CUST_TOTAL_QUANTITY,PNL.PRODUCT_NAMEFROMGOSALESCT.CUST_ORDER_HEADER COHINNERJOINGOSALESCT.CUST_ORDER_DETAIL CODONCOH.CUST_ORDER_NUMBER = COD.CUST_ORDER_NUMBERINNERJOINGOSALES.PRODUCT_NAME_LOOKUP PNLONPNL.PRODUCT_NUMBER = COD.PRODUCT_NUMBERWHERE CUST_CODE = CUST_CODEAND PNL.PRODUCT_LANGUAGE =ENCUST_CODE CUST_NAME CUST_AGE CUST_ORDER_DATE CUST_ORDER_NUMBER CUST_TOTAL CUST_SALES_TAX CUST_TOTAL_QUANTITY PRODUCT_NAME--------- ------------------------------------ -------- --------------------------- ----------------- ---------- -------------- ------------------- ---------------------------------102919 Bob,Bass 29 Sunday-10-June-2007 189092 648.24 27.91 2 Star Lite102919 Bob,Bass 29 Sunday-10-June-2007 189092 648.24 27.91 2 Hibernator Lite107086 Linus,Hedberg 47 Wednesday-01-December-2004 118797 1069.61 41.14 3 TrailChef Kitchen Kit107086 Linus,Hedberg 47 Wednesday-01-December-2004 118797 1069.61 41.14 3 Canyon Mule Extreme Backpack107086 Linus,Hedberg 47 Wednesday-01-December-2004 118797 1069.61 41.14 3 Hawk Eye123731 Jenny,Andersson 34 Monday-10-July-2006 162173 2603.30 520.66 1 Hailstorm Titanium Irons118873 Mary,Honeycutt 56 Tuesday-25-April-2006 149579 189.90 14.47 1 Seeker 50125520 Amir,Kumar 44 Saturday-23-September-2006 166790 2266.29 251.81 8 Husky Harness Extreme125520 Amir,Kumar 44 Saturday-23-September-2006 166790 2266.29 251.81 8 Hibernator Pillow125520 Amir,Kumar 44 Saturday-23-September-2006 166790 2266.29 251.81 8 Husky Rope 100125520 Amir,Kumar 44 Saturday-23-September-2006 166790 2266.29 251.81 8 Hibernator Lite125520 Amir,Kumar 44 Saturday-23-September-2006 166790 2266.29 251.81 8 Hibernator125520 Amir,Kumar 44 Saturday-23-September-2006 166790 2266.29 251.81 8 Hibernator Extreme111197 Ralph,Hunter 43 Tuesday-24-May-2005 129627 171.52 0.00 2 Canyon Mule CarryallResult AbridgedCREATEFUNCTIONORDER_REC()RETURNSTABLE(CUST_CODE INTEGER,CUST_FIRST_NAME VARCHAR(90),CUST_LAST_NAME VARCHAR(90),CUST_ORDER_DATE VARCHAR(55),CUST_ORDER_NUMBER INTEGER,CUST_SALES_TAX DECIMAL,CUST_SHIP_COST DECIMAL,CUST_SUB_TOTAL DECIMAL,TOTAL_QUANTITY BIGINT)NOTDETERMINISTICLANGUAGESQLCALLEDONNULLINPUTRETURNSELECTC.CUST_CODE, C.CUST_FIRST_NAME, C.CUST_LAST_NAME,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)AS CUST_ORDER_DATE,COH.CUST_ORDER_NUMBER, COH.CUST_SALES_TAX,COH.CUST_SHIP_COST, COH.CUST_SUBTOTAL, COH.CUST_TOTAL_QUANTITYFROM GOSALESCT.CUST_CUSTOMER CINNERJOINGOSALESCT.CUST_ORDER_HEADER COHONCOH.CUST_CODE =C.CUST_CODE;SELECT * FROM TABLE(ORDER_REC())AS CUST_REC;CUST_CODE CUST_FIRST_NAME CUST_LAST_NAME CUST_ORDER_DATE CUST_ORDER_NUMBER CUST_SALES_TAX CUST_SHIP_COST CUST_SUB_TOTAL TOTAL_QUANTITY--------- ----------------- -------------------- --------------------------- ----------------- -------------- -------------- -------------- --------------126909 AyakaMiyamura Tuesday-21-November-2006 170389 11 8 68 1126920 VikentiyProkofiyov Friday-01-December-2006 170420 222 12 1223 5126941 Edith Lapointe Sunday-19-November-2006 170478 76 5 504 1126986 Jeffrey Hall Wednesday-22-November-2006 170599 21 8 173 2127080 Enrico Vanni Wednesday-06-December-2006 170842 25 8 123 1127206 Massimo Ripetto Thursday-14-December-2006 171177 516 19 2564 3127288 Meghan Clay Thursday-21-December-2006 171381 4 5 34 1Result AbridgedCREATEFUNCTION ORDER_REC2(@CUSTID INTEGER)RETURNSTABLE(CUST_CODE INTEGER,CUST_FIRST_NAME VARCHAR(90),CUST_LAST_NAME VARCHAR(90),CUST_ORDER_DATE VARCHAR(55),CUST_ORDER_NUMBER INTEGER,CUST_SALES_TAX DECIMAL,CUST_SHIP_COST DECIMAL,CUST_SUB_TOTAL DECIMAL,TOTAL_QUANTITY BIGINT)NOTDETERMINISTICLANGUAGESQLRETURNSELECTC.CUST_CODE, C.CUST_FIRST_NAME, C.CUST_LAST_NAME,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)AS CUST_ORDER_DATE,COH.CUST_ORDER_NUMBER, COH.CUST_SALES_TAX,COH.CUST_SHIP_COST, COH.CUST_SUBTOTAL, COH.CUST_TOTAL_QUANTITYFROM GOSALESCT.CUST_CUSTOMER CINNERJOINGOSALESCT.CUST_ORDER_HEADER COHON
    • 15COH.CUST_CODE =C.CUST_CODEWHEREC.CUST_CODE = @CUSTID;SELECT * FROM TABLE(ORDER_REC2(126906))AS CUST_REC;CUST_CODE CUST_FIRST_NAME CUST_LAST_NAME CUST_ORDER_DATE CUST_ORDER_NUMBER CUST_SALES_TAX CUST_SHIP_COST CUST_SUB_TOTAL TOTAL_QUANTITY--------- --------------- -------------- ------------------------- ----------------- -------------- -------------- -------------- --------------126906 Nick Dunphy Thursday-09-November-2006 170381 10 8 179 1Lists of functions created as viewed in Microsoft Visual Studio 2010
    • 16Data DefinitionCREATETABLE GOSALESCT.CUST_ORDER_REC( REC_ID INTEGERNOTNULLPRIMARYKEYGENERATEDALWAYSASIDENTITY(STARTWITH 0903 INCREMENTBY 20),cust_codeINTEGERNOTNULL,cust_nameVARCHAR(220),cust_order_numberINTEGERNOTNULL,order_dateVARCHAR(80),cust_sales_taxDECIMAL(19,2),cust_ship_costDECIMAL(19,2),cust_subtotalDECIMAL(19,2),cust_totalDECIMAL(19,2),cust_total_quantityINTEGER,crdt_method_codeINTEGER,card_expdateVARCHAR(50),cust_cc_idINTEGER,product_numberINTEGER,product_namevarchar(240));CREATETABLE GOSALESCT.CUST_ORDER_ADUIT( REC_ID INTEGER,cust_codeINTEGER ,cust_nameVARCHAR(220),cust_order_numberINTEGER ,order_dateVARCHAR(80),cust_sales_taxDECIMAL(19,2),cust_ship_costDECIMAL(19,2),cust_subtotalDECIMAL(19,2),cust_totalDECIMAL(19,2),cust_total_quantityINTEGER,crdt_method_codeINTEGER,card_expdateVARCHAR(50),cust_cc_idINTEGER,product_numberINTEGER,product_namevarchar(240),AUDIT_ID INTEGERNOTNULLPRIMARYKEYGENERATEDALWAYSASIDENTITY(STARTWITH 0903 INCREMENTBY 20),ACTION_TYPE CHAR(40),ACTION_DATE TIMESTAMPDEFAULTCURRENTTIMESTAMP);CREATEVIEW GOSALESCT.SALES_VWASSELECT COH.CUST_CODE, CUST.CUST_FIRST_NAME CONCAT,CONCAT CUST.CUST_LAST_NAME ASCust_Name,COH.CUST_ORDER_NUMBER ,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)ASOrder_Date,COH.CUST_SALES_TAX asSales_Tax, COH.CUST_SHIP_COST, COH.CUST_SUBTOTAL,COH.CUST_TOTAL, COH.CUST_TOTAL_QUANTITY,CRTCD.CRDT_METHOD_CODE ,VARCHAR_FORMAT(CRTCD.CUST_CC_EXP_DATE, Day-dd-Month-YYYY)ASCard_ExpDate,CRTCD.cust_cc_id,PRD.PRODUCT_NUMBER,PRD.product_NAMEFROM GOSALESCT.CUST_CUSTOMER CUSTINNERJOIN GOSALESCT.CUST_ORDER_HEADER COHONCUST.CUST_CODE = COH.CUST_CODEINNERJOIN GOSALESCT.CUST_CRDT_CARD CRTCDONCUST.CUST_CODE = CRTCD.CUST_CODEINNERJOIN GOSALESCT.CUST_ORDER_DETAIL CODONCOD.CUST_ORDER_NUMBER = COH.CUST_ORDER_NUMBERINNERJOINGOSALES.PRODUCT_NAME_LOOKUP PRDON COD.PRODUCT_NUMBER = PRD.PRODUCT_NUMBERWHERE PRD.PRODUCT_LANGUAGE =EN
    • 17SELECT * FROM GOSALESCT.SALES_VW FETCH FIRST 15 ROWS ONLY;CUST_CODECUST_NAME CUST_ORDER_NUMBER ORDER_DATE SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME131090 Sonya,Widerberg 100039 Wednesday-14-January-200443.03 6.92 165.18 215.12 2 28 Wednesday-01-December-201010017 87110 BugShield Spray131090 Sonya,Widerberg 100039 Wednesday-14-January-200443.03 6.92 165.18 215.12 2 28 Wednesday-01-December-201010017 78110 Seeker 35131156 Wei,Xi 100201 Thursday-29-January-2004 14.24 5.87 77.89 98 1 29 Sunday-01-May-2011 10081 143150 Trendi131168 Elena,Nilina 100227 Saturday-24-January-2004 15.8 5.87 81.9 103.57 1 29 Friday-01-January-2010 10092 136150 Sam131210 Achim,Bergmann 100329 Friday-02-January-2004 503.9 9.84 2509.66 3023.4 2 29 Monday-01-July-2013 10134 110110 Blue Steel Putter131210 Achim,Bergmann 100329 Friday-02-January-2004 503.9 9.84 2509.66 3023.4 2 29 Monday-01-July-2013 10134 106110 Hailstorm Steel Woods Set100008 Alphonse,Bobert 100463 Thursday-22-January-2004 1.76 7.94 27.17 36.87 1 28 Tuesday-01-May-2012 10187 9110 TrailChef Kettle100026 Bryce,Denver 100507 Thursday-01-January-2004 56.51 13.97 551.13 621.61 1 25 Saturday-01-December-2012 10205 44110 Husky Rope 100100062 Yi,Dong 100602 Sunday-18-January-2004 8.06 5.87 155.38 169.31 1 28 Thursday-01-July-2010 10240 68120 Polar Sun100142 Ruben,Raisaov 100801 Thursday-01-January-2004 434.73 9.84 2405.34 2849.91 2 25 Tuesday-01-December-2009 10317 106110 Hailstorm Steel Woods Set100142 Ruben,Raisaov 100801 Thursday-01-January-2004 434.73 9.84 2405.34 2849.91 2 25 Tuesday-01-December-2009 10317 109110 Course Pro Putter100160 Kan,Shang 100846 Friday-30-January-2004 675.42 13.29 3959.76 4648.47 4 29 Friday-01-March-2013 10335 101110 Hailstorm Steel Irons100160 Kan,Shang 100846 Friday-30-January-2004 675.42 13.29 3959.76 4648.47 4 29 Friday-01-March-2013 10335 106110 Hailstorm Steel Woods Set100160 Kan,Shang 100846 Friday-30-January-2004 675.42 13.29 3959.76 4648.47 4 29 Friday-01-March-2013 10335 109110 Course Pro Putter100160 Kan,Shang 100846 Friday-30-January-2004 675.42 13.29 3959.76 4648.47 4 29 Friday-01-March-2013 10335 111110 Blue Steel Max Putter
    • 18Stored ProceduresCREATEPROCEDUREGOSALESCT.Order_Rec()LANGUAGESQLDYNAMICRESULTSETS 1READSSQLDATANOTDETERMINISTICCALLEDONNULLINPUTBEGINDECLARE CUSTORDER CURSORWITHRETURNFORSELECT COH.CUST_CODE, CUST.CUST_FIRST_NAME CONCAT,CONCAT CUST.CUST_LAST_NAME ASCust_Name,COH.CUST_ORDER_NUMBER ,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)ASOrder_Date,COH.CUST_SALES_TAX asSales_Tax, COH.CUST_SHIP_COST, COH.CUST_SUBTOTAL,COH.CUST_TOTAL, COH.CUST_TOTAL_QUANTITY,CRTCD.CRDT_METHOD_CODE ,VARCHAR_FORMAT(CRTCD.CUST_CC_EXP_DATE, Day-dd-Month-YYYY)ASCard_ExpDate,CRTCD.cust_cc_id,PRD.PRODUCT_NUMBER,PRD.product_NAMEFROM GOSALESCT.CUST_CUSTOMER CUSTINNERJOIN GOSALESCT.CUST_ORDER_HEADER COHONCUST.CUST_CODE = COH.CUST_CODEINNERJOIN GOSALESCT.CUST_CRDT_CARD CRTCDONCUST.CUST_CODE = CRTCD.CUST_CODEINNERJOIN GOSALESCT.CUST_ORDER_DETAIL CODONCOD.CUST_ORDER_NUMBER = COH.CUST_ORDER_NUMBERINNERJOINGOSALES.PRODUCT_NAME_LOOKUP PRDON COD.PRODUCT_NUMBER = PRD.PRODUCT_NUMBERWHERE PRD.PRODUCT_LANGUAGE =EN;OPEN CUSTORDER;ENDCUST_CODE CUST_NAME CUST_ORDER_NUMBER ORDER_DATE SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBERPRODUCT_NAME--------- ------------------------------------ ----------------- -------------------------- --------- -------------- ------------- ---------- ------------------- ---------------- --------------------------- ---------- -------------- ---------------------------------131090 Sonya,Widerberg 100039 Wednesday-14-January-2004 43.03 6.92 165.18 215.12 2 28 Wednesday-01-December-2010 10017 87110BugShield Spray131090 Sonya,Widerberg 100039 Wednesday-14-January-2004 43.03 6.92 165.18 215.12 2 28 Wednesday-01-December-2010 10017 78110Seeker 35131156 Wei,Xi 100201 Thursday-29-January-2004 14.24 5.87 77.89 98.00 1 29 Sunday-01-May-2011 10081 143150Trendi131168 Elena,Nilina 100227 Saturday-24-January-2004 15.80 5.87 81.90 103.57 1 29 Friday-01-January-2010 10092 136150 Sam131210 Achim,Bergmann 100329 Friday-02-January-2004 503.90 9.84 2509.66 3023.40 2 29 Monday-01-July-2013 10134 110110 BlueSteel PutterResult AbridgedCREATEPROCEDURE GOSALESCT.Order_Rec3(IN @CUSTID INTEGER)LANGUAGESQLDYNAMICRESULTSETS 1READSSQLDATANOTDETERMINISTICBEGINDECLARE CUSTORDER CURSORWITHRETURNFORSELECT COH.CUST_CODE, CUST.CUST_FIRST_NAME CONCAT,CONCAT CUST.CUST_LAST_NAME ASCust_Name,COH.CUST_ORDER_NUMBER ,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)ASOrder_Date,COH.CUST_SALES_TAX asSales_Tax, COH.CUST_SHIP_COST, COH.CUST_SUBTOTAL,COH.CUST_TOTAL, COH.CUST_TOTAL_QUANTITY,CRTCD.CRDT_METHOD_CODE ,VARCHAR_FORMAT(CRTCD.CUST_CC_EXP_DATE, Day-dd-Month-YYYY)ASCard_ExpDate,CRTCD.cust_cc_id,PRD.PRODUCT_NUMBER,PRD.product_NAMEFROM GOSALESCT.CUST_CUSTOMER CUSTINNERJOIN GOSALESCT.CUST_ORDER_HEADER COHONCUST.CUST_CODE = COH.CUST_CODEINNERJOIN GOSALESCT.CUST_CRDT_CARD CRTCDONCUST.CUST_CODE = CRTCD.CUST_CODEINNERJOIN GOSALESCT.CUST_ORDER_DETAIL CODONCOD.CUST_ORDER_NUMBER = COH.CUST_ORDER_NUMBERINNERJOINGOSALES.PRODUCT_NAME_LOOKUP PRDON COD.PRODUCT_NUMBER = PRD.PRODUCT_NUMBERWHERE PRD.PRODUCT_LANGUAGE =ENAND CUST.CUST_CODE = @CUSTID;OPEN CUSTORDER;ENDCUST_CODE CUST_NAME CUST_ORDER_NUMBER ORDER_DATE SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME--------- ------------ ----------------- ------------------------- --------- -------------- ------------- ---------- ------------------- ---------------- ------------------------- ---------- -------------- ----------------------131100 Zinia,Jarvis 100063 Wednesday-07-January-2004 2.68 5.57 35.70 43.95 1 28 Tuesday-01-September-2009 10026 124130 Cat Eye131100 Zinia,Jarvis 181181 Tuesday-24-April-2007 21.09 9.53 314.93 345.55 2 28 Tuesday-01-September-2009 10026 8110 TrailChef Double Flame131100 Zinia,Jarvis 181181 Tuesday-24-April-2007 21.09 9.53 314.93 345.55 2 28 Tuesday-01-September-2009 10026 9110 TrailChef KettleTable PopulationCREATEPROCEDURE GOSALESCT.Order_Rec4(IN @CUSTID INTEGER)LANGUAGESQLDYNAMICRESULTSETS 1MODIFIESSQLDATANOTDETERMINISTICBEGINATOMIC
    • 19INSERTINTO GOSALESCT.CUST_ORDER_REC(cust_code,cust_name,cust_order_number,order_date,cust_sales_tax,cust_ship_cost,cust_subtotal,cust_total,cust_total_quantity,crdt_method_code,card_expdate,cust_cc_id,product_number,product_name)SELECT COH.CUST_CODE, CUST.CUST_FIRST_NAME CONCAT,CONCAT CUST.CUST_LAST_NAME ASCust_Name,COH.CUST_ORDER_NUMBER ,VARCHAR_FORMAT(COH.CUST_ORDER_DATE,Day-dd-Month-YYYY)ASOrder_Date,COH.CUST_SALES_TAX asSales_Tax, COH.CUST_SHIP_COST, COH.CUST_SUBTOTAL,COH.CUST_TOTAL, COH.CUST_TOTAL_QUANTITY,CRTCD.CRDT_METHOD_CODE ,VARCHAR_FORMAT(CRTCD.CUST_CC_EXP_DATE, Day-dd-Month-YYYY)ASCard_ExpDate,CRTCD.cust_cc_id,PRD.PRODUCT_NUMBER,PRD.product_NAMEFROM GOSALESCT.CUST_CUSTOMER CUSTINNERJOIN GOSALESCT.CUST_ORDER_HEADER COHONCUST.CUST_CODE = COH.CUST_CODEINNERJOIN GOSALESCT.CUST_CRDT_CARD CRTCDONCUST.CUST_CODE = CRTCD.CUST_CODEINNERJOIN GOSALESCT.CUST_ORDER_DETAIL CODONCOD.CUST_ORDER_NUMBER = COH.CUST_ORDER_NUMBERINNERJOINGOSALES.PRODUCT_NAME_LOOKUP PRDON COD.PRODUCT_NUMBER = PRD.PRODUCT_NUMBERWHERE PRD.PRODUCT_LANGUAGE =ENAND CUST.CUST_CODE = @CUSTID;ENDCALL Order_Rec4(100117);SELECT * FROM GOSALESCT.CUST_ORDER_REC;REC_ID CUST_CODE CUST_NAME CUST_ORDER_NUMBERORDER_DATE CUST_SALES_TAXCUST_SHIP_COSTCUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME903 100117 Zizi,Vila Rangel 100738 Friday-30-January-2004 23.36 9.16 102.09 134.61 2 25 Thursday-01-March-2012 10292 28110 Canyon MuleCooler923 100117 Zizi,Vila Rangel 100738 Friday-30-January-2004 23.36 9.16 102.09 134.61 2 25 Thursday-01-March-2012 10292 3110 TrailChef KitchenKit943 100117 Zizi,Vila Rangel 181893 Sunday-01-April-2007 4.61 7.33 14.61 26.55 1 25 Thursday-01-March-2012 10292 1110 TrailChef WaterBagCREATEPROCEDUREGOSALESCT.Order_Rec_update( IN @CUSTID INTEGER,IN @PRODID INTEGER,IN @SALTX DECIMAL(19,2) )LANGUAGESQLDYNAMICRESULTSETS 1MODIFIESSQLDATANOTDETERMINISTICBEGINATOMICUPDATE GOSALESCT.CUST_ORDER_RECSETcust_sales_tax = @SALTXWHEREcust_code= @CUSTID ANDproduct_number = @PRODID;ENDCALL GOSALESCT.Order_Rec_update(100117,28110,25);REC_ID CUST_CODE CUST_NAME CUST_ORDER_NUMBER ORDER_DATE CUST_SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME903 100117 Zizi,VilaRangel100738 Friday-30-January-200425 9.16 102.09 134.61 2 25 Thursday-01-March-201210292 28110 Canyon MuleCooler923 100117 Zizi,VilaRangel100738 Friday-30-January-200423.36 9.16 102.09 134.61 2 25 Thursday-01-March-201210292 3110 TrailChef KitchenKit943 100117 Zizi,VilaRangel181893 Sunday-01-April-20074.61 7.33 14.61 26.55 1 25 Thursday-01-March-201210292 1110 TrailChef WaterBagSince the Rec_ID was not used in the procedure. The stored procedure could update multiple rows since a customer may purchase a product multiple times. To avoid this problem, the following delete procedure and update procedure 2 has to include theRec_IDcreatePROCEDUREGOSALESCT.Order_Rec_delete( IN @CUSTID INTEGER,IN @PRODID INTEGER,IN @RECID INTEGER)LANGUAGESQLDYNAMICRESULTSETS 1MODIFIESSQLDATANOTDETERMINISTICCALLEDONNULLINPUTBEGINATOMICdelete GOSALESCT.CUST_ORDER_RECWHEREcust_code= @CUSTIDANDproduct_number = @PRODIDAND REC_ID = @RECID;END
    • 20createPROCEDURE GOSALESCT.Order_Rec_update2( IN @CUSTID INTEGER,IN @PRODID INTEGER,IN @RECID INTEGER,IN @TX DECIMAL(19,2))LANGUAGESQLDYNAMICRESULTSETS 1MODIFIESSQLDATANOTDETERMINISTICCALLEDONNULLINPUTBEGINATOMICupdate GOSALESCT.CUST_ORDER_RECsetcust_sales_tax =@TXWHEREcust_code= @CUSTIDANDproduct_number = @PRODIDAND REC_ID = @RECID;ENDCALL GOSALESCT.Order_Rec_delete(100117, 1110,943);CALL GOSALESCT.Order_Rec_update2(100117,3110, 923,45);SELECT * FROM GOSALESCT.CUST_ORDER_REC;REC_ID CUST_CODE CUST_NAME CUST_ORDER_NUMBERORDER_DATE CUST_SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME903 100117 Zizi,Vila Rangel 100738 Friday-30-January-200425 9.16 102.09 134.61 2 25 Thursday-01-March-2012 10292 28110 Canyon Mule Cooler923 100117 Zizi,Vila Rangel 100738 Friday-30-January-200445 9.16 102.09 134.61 2 25 Thursday-01-March-2012 10292 3110 TrailChef Kitchen KitList of Storedprocedures from Microsoft Visual Studios 2010.IBM Data Studio Workspace
    • 21TriggersCREATETRIGGER GOSALESCT.RECORD_INSERTAFTERINSERTON GOSALESCT.CUST_ORDER_RECREFERENCINGNEWAS INSERTEDFOREACHROWMODEDB2SQLINSERTINTO GOSALESCT.CUST_ORDER_ADUIT (REC_ID,cust_code,cust_name,cust_order_number,order_date,cust_sales_tax,cust_ship_cost,cust_subtotal,cust_total,cust_total_quantity,crdt_method_code,card_expdate,cust_cc_id,product_number,product_name, ACTION_TYPE)VALUES(INSERTED.REC_ID,INSERTED.cust_code,INSERTED.cust_name,INSERTED.cust_order_number,INSERTED.order_date,INSERTED.cust_sales_tax,INSERTED.cust_ship_cost,INSERTED.cust_subtotal,INSERTED.cust_total,INSERTED.cust_total_quantity,INSERTED.crdt_method_code,INSERTED.card_expdate,INSERTED.cust_cc_id,INSERTED.product_number,INSERTED.product_name, INSERT);Execute the previous stored procedure used to populate cust_order_rec table.CALL Order_Rec4(100185);Select * from cust_order_rec table;REC_ID CUST_CODECUST_NAME CUST_ORDER_NUMBERORDER_DATECUST_SALES_TAXCUST_SHIP_COSTCUST_SUBTOTALCUST_TOTALCUST_TOTAL_QUANTITYCRDT_METHOD_CODECARD_EXPDATECUST_CC_IDPRODUCT_NUMBERPRODUCT_NAME903 100117 Zizi,VilaRangel100738 Friday-30-January-200425 9.16 102.09 134.61 2 25 Thursday-01-March-201210292 28110 Canyon MuleCooler923 100117 Zizi,VilaRangel100738 Friday-30-January-200445 9.16 102.09 134.61 2 25 Thursday-01-March-201210292 3110 TrailChef KitchenKit963 100185 Jeff,Canon 100910 Thursday-29-January-20041.53 5.57 16.33 23.43 1 28 Sunday-01-September-201310359 73110 Single Edge983 100185 Jeff,Canon 182071 Wednesday-18-April-20071.82 5.87 20.08 27.77 1 28 Sunday-01-September-201310359 73110 Single EdgeSELECT * FROM GOSALESCT.CUST_ORDER_ADUIT;REC_ID CUST_CODE CUST_NAME CUST_ORDER_NUMBER ORDER_DATE CUST_SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME AUDIT_IDACTION_TYPE ACTION_DATE------ --------- ---------- ----------------- ------------------------ -------------- -------------- ------------- ---------- ------------------- ---------------- ------------------------ ---------- -------------- ------------ -------- ---------------------------------------- -----------------------963 100185 Jeff,Canon 100910 Thursday-29-January-2004 1.53 5.57 16.33 23.43 1 28 Sunday-01-September-2013 10359 73110 Single Edge 903INSERT 2013-04-22 06:52:09.123983 100185 Jeff,Canon 182071 Wednesday-18-April-2007 1.82 5.87 20.08 27.77 1 28 Sunday-01-September-2013 10359 73110 Single Edge 923INSERT 2013-04-22 06:52:09.123CREATETRIGGER GOSALESCT.RECORD_DELETEAFTERDELETEON GOSALESCT.CUST_ORDER_RECREFERENCINGOLDAS DELETEDFOREACHROWMODEDB2SQLINSERTINTO GOSALESCT.CUST_ORDER_ADUIT (REC_ID,cust_code,cust_name,cust_order_number,order_date,cust_sales_tax,cust_ship_cost,cust_subtotal,cust_total,cust_total_quantity,crdt_method_code,card_expdate,cust_cc_id,product_number,product_name, ACTION_TYPE)VALUES(DELETED.REC_ID,DELETED.cust_code,DELETED.cust_name,DELETED.cust_order_number,DELETED.order_date,DELETED.cust_sales_tax,DELETED.cust_ship_cost,DELETED.cust_subtotal,DELETED.cust_total,DELETED.cust_total_quantity,DELETED.crdt_method_code,DELETED.card_expdate,DELETED.cust_cc_id,DELETED.product_number,DELETED.product_name, DELETE);CALL GOSALESCT.Order_Rec_delete(100185, 73110, 963 );Select * from cust_order_rec table;REC_ID CUST_CODE CUST_NAME CUST_ORDER_NUMBER ORDER_DATE CUST_SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME903 100117 Zizi,Vila Rangel 100738 Friday-30-January-2004 25 9.16 102.09 134.61 2 25 Thursday-01-March-2012 10292 28110 Canyon Mule Cooler923 100117 Zizi,Vila Rangel 100738 Friday-30-January-2004 45 9.16 102.09 134.61 2 25 Thursday-01-March-2012 10292 3110 TrailChef Kitchen Kit983 100185 Jeff,Canon 182071 Wednesday-18-April-2007 1.82 5.87 20.08 27.77 1 28 Sunday-01-September-201310359 73110 Single EdgeSELECT * FROM GOSALESCT.CUST_ORDER_ADUIT;
    • 22REC_ID CUST_CODE CUST_NAME CUST_ORDER_NUMBER ORDER_DATE CUST_SALES_TAX CUST_SHIP_COST CUST_SUBTOTAL CUST_TOTAL CUST_TOTAL_QUANTITY CRDT_METHOD_CODE CARD_EXPDATE CUST_CC_ID PRODUCT_NUMBER PRODUCT_NAME AUDIT_IDACTION_TYPE ACTION_DATE------ --------- ---------- ----------------- ------------------------ -------------- -------------- ------------- ---------- ------------------- ---------------- ------------------------ ---------- -------------- ------------ -------- ---------------------------------------- -----------------------963 100185 Jeff,Canon 100910 Thursday-29-January-2004 1.53 5.57 16.33 23.43 1 28 Sunday-01-September-2013 10359 73110 Single Edge 903INSERT 2013-04-22 06:52:09.123983 100185 Jeff,Canon 182071 Wednesday-18-April-2007 1.82 5.87 20.08 27.77 1 28 Sunday-01-September-2013 10359 73110 Single Edge 923INSERT 2013-04-22 06:52:09.123963 100185 Jeff,Canon 100910 Thursday-29-January-2004 1.53 5.57 16.33 23.43 1 28 Sunday-01-September-2013 10359 73110 Single Edge 943DELETE 2013-04-22 07:15:04.816List of triggers created as displayed in Oracle JDEVELOEPER
    • 23
    • 24
    • 25