Instruction_on_Creating_sql_and_SPOOL.pptx

download Instruction_on_Creating_sql_and_SPOOL.pptx

of 12

Transcript of Instruction_on_Creating_sql_and_SPOOL.pptx

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    1/12

    Dr. Chen, Busin ess Database Systems (Oracle)

    Instruction on Creating

    sql files and SPOOL

    Jason C.H. Chen,Ph.D.

    Professor of MIS

    School of Business, Gonzaga UniversitySpokane, WA 99258 USA

    [email protected]

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    2/12

    Dr. Chen, Busin ess Database Systems (Oracle)2

    HW

    Create a *.sql script file using Notepad for the Hands-

    On Assignments (#3,5,7,9 and 1) on pp. 54-55 (why

    #1 at the end?)

    Name your file as Oracle_Ch2_Lname_Fname.sql

    (not .txt). For example, Oracle_Ch2_chen_Jason.sql Make sure the file extension should be *.sql not *.txt,

    otherwise, you cant do other commands in the future.

    How? See detailed instruction on the next slide.

    Note that you need to copy and paste each sql file to

    SQL> (SQL Plus) and make sure each one is working

    properly.

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    3/12

    Dr. Chen, Busin ess Database Systems (Oracle)

    Instruction on Creating a Script file and save as *.sql file

    Step 1. Create SQL commands using Notepad

    Step 2. Click File then Save As..

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    4/12

    Dr. Chen, Busin ess Database Systems (Oracle)

    Instruction on Creating a Script file and save as *.sql file (cont.)

    Step 3. Save AS Screen

    Step 4. Change from Text Document ( *.txt) to

    All Files (*.*) on Save as type box

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    5/12

    Dr. Chen, Busin ess Database Systems (Oracle)

    Instruction on Creating a Script file and save as *.sql file (cont.)

    Step 5. Enter a right file name (Oracle_Ch2_Chen_Jason.sql)

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    6/12

    Dr. Chen, Busin ess Database Systems (Oracle)6

    HW (cont.)

    Then spool it onto the file ofOracle_ch2_Spool_Chen_Jason.txt

    How?

    See next slide

    Please note that the SPOOLed file should includeboth your source sql commands and the result fromthe Oracle.

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    7/12Dr. Chen, Busin ess Database Systems (Oracle)7

    How to Spool your Script and Output Files

    After you tested the script file of Oracle_ch2_Lname_Fname.sql successfully,follow the instructions below to spool both script and output files:

    Step 0. Run the following two script files from SQL*Plus (since you havecreated JLDB tables)

    Start c:\oradata\chapter2\JLDB_Drop.sql

    Start c:\oradata\chapter2\JLDB_Build.sql

    1. type the following on SQL>

    Spool c:\oradata\Oracle_ch2_Spool_Lname_Fname.txt(make sure your name is entered) 2. open Oracle_ch2_Lname_Fname.sql that you already tested

    3. copy and paste all the SQL commands (including all comments) to theSQL*PLUS

    4. type Spool Off on the SQL>

    The output should contain your personal information, all SQL commands andtheir solution on the .txt file and saved in C: drive (oradata\ folder)

    Email me the spooled file (.txt) with attachment to:

    [email protected]

    with subject title of

    bmis441_Oracle_ch2

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    8/12Dr. Chen, Busin ess Database Systems (Oracle)

    Hint for #1:

    Advanced SQL Commandsclear screen;

    column format a15 wrapcolumn format a15 word

    column format a20 heading description for the field

    column format a15 truncate

    column format $999.99

    -- note: default is wrap

    -- formatting output (try it on the SQL>)

    -- chapter 2, Figure 2-14(b); p. 41

    clear screen

    SET LINESIZE 80

    SET PAGESIZE 45column title format a12 heading 'Book Title' WORD

    column PubID format 99 heading 'ID'

    column Cost format $999.99

    column retail format $999.99

    SELECT *

    FROM books;

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    9/12Dr. Chen, Busin ess Database Systems (Oracle)

    ISBN Book Title PUBDATE ID COST RETAIL DISCOUNT CATEGORY

    ---------- ------------ --------- --- -------- -------- ---------- ------------

    1059831198 BODYBUILD IN 21-JAN-05 4 $18.75 $30.95 FITNESS

    10 MINUTES

    A DAY

    0401140733 REVENGE OF M 14-DEC-05 1 $14.20 $22.00 FAMILY LIFE

    ICKEY

    4981341710 BUILDING A C 18-MAR-06 2 $37.80 $59.95 3 CHILDREN

    AR WITH TOOT

    HPICKS

    8843172113 DATABASE IMP 04-JUN-03 3 $31.40 $55.95 COMPUTER

    LEMENTATION

    3437212490 COOKING WITH 28-FEB-04 4 $12.50 $19.95 COOKING

    MUSHROOMS

    3957136468 HOLY GRAIL O 31-DEC-05 3 $47.25 $75.95 3.8 COMPUTER

    F ORACLE

    1915762492 HANDCRANKED 21-JAN-05 3 $21.80 $25.00 COMPUTER

    COMPUTERS

    9959789321 E-BUSINESS T 01-MAR-06 2 $37.90 $54.50 COMPUTER

    HE EASY WAY

    2491748320 PAINLESS CHI 17-JUL-04 5 $48.00 $89.95 4.5 FAMILY LIFE

    LD-REARING

    0299282519 THE WOK WAY 11-SEP-04 4 $19.00 $28.75 COOKING

    TO COOK

    8117949391 BIG BEAR AND 08-NOV-05 5 $5.32 $8.95 CHILDREN

    LITTLE DOVE

    0132149871 HOW TO GET F 11-NOV-06 4 $17.85 $29.95 1.5 SELF HELP

    ASTER PIZZA9247381001 HOW TO MANAG 09-MAY-03 1 $15.40 $31.95 BUSINESS

    E THE MANAGE

    R

    ISBN Book Title PUBDATE ID COST RETAIL DISCOUNT CATEGORY

    ---------- ------------ --------- --- -------- -------- ---------- ------------

    2147428890 SHORTEST POE 01-MAY-05 5 $21.85 $39.95 LITERATURE

    MS

    14 rows selected.

    Here is a better output after formatting output:

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    10/12Dr. Chen, Busin ess Database Systems (Oracle)

    Summary on Oracle_Ch2

    - see spool instruction on the next slideHW (Odd numbers only (pp.54-55), but do #1 at the end as it will affects therest of problems)

    - run the following two commands:Start c:\oradata\chapter2\JLDB_Drop.sql

    Start c:\oradata\chapter2\JLDB_Build.sqlOutput should be formatted in a very good manner.

    Scripting file name: Oracle_ch2_Lname_Fname.sql

    Spooled file name: Oracle_ch2_Spool_Lname_Fname.txt

    Email me with the spooled file using attachment to:

    [email protected]

    with subject title of

    bmis441_Oracle_ch2

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    11/12Dr. Chen, Busin ess Database Systems (Oracle)

    Summary on Oracle_Ch2 (cont.)

    Read and Practice all examples on Chapters 2

    1. Run two script files: JLDB_Drop.sql and

    JLDB_Build.sql 2. Read Oracle assignment and create a script file

    Oracle_ch2_Lname_Fname.sql for odd numberquestions on Hands-on Assignments. Use appropriateCOLUMNstatements to produce readable outputs

    3. Execute and test one problem a time (do #1 at the

    end, why?) and make sure they are all runningsuccessfully. Include class andpersonal information.

    4. When you done, spool the script files (see next slidefor spooling instructions) and email the file(Oracle_ch2_Spool_Lname_Fname.txt) to me by themidnight before the next class. Turn in a hardcopy to

    me in the class.

    Email me with one attachment

    (Oracle_ch2_Spool_Lname_Fname.) to:

    [email protected] subject title of

    bmis441_Oracle_ch2

  • 8/10/2019 Instruction_on_Creating_sql_and_SPOOL.pptx

    12/12Dr. Chen, Busin ess Database Systems (Oracle)

    12

    How to Spool your Script and Output Files

    After you tested the script file of Oracle_ch2_Lname_Fname.sql successfully,follow the instructions below to spool both script and output files:

    Step 0. Run the following two script files from SQL*Plus (since you havecreated JLDB tables)

    Start c:\oradata\chapter2\JLDB_Drop.sql

    Start c:\oradata\chapter2\JLDB_Build.sql

    1. type the following on SQL>

    Spool c:\oradata\Oracle_ch2_Spool_Lname_Fname.txt(make sure your name is entered) 2. open Oracle_ch2_Lname_Fname.sql that you already tested

    3. copy and paste all the SQL commands (including all comments) to theSQL*PLUS

    4. type Spool Off on the SQL>

    The output should contain your personal information, all SQL commands andtheir solution on the .txt file and saved in C: drive (oradata\ folder)

    Email me the spooled file (.txt) with attachment to:

    [email protected]

    with subject title of

    bmis441_Oracle_ch2