Sei sulla pagina 1di 17

Practice Practice 1 1. Initiate an iSQL*Plus session using the user ID and password provided by the instructor. 2. .

iSQL*Plus commands access the database. !he "ollowing S#L#$! statement e%ecutes success"ully& +,-. 0. S#L#$! last'name( )ob'id( salary *S Sal employees/

!he "ollowing S#L#$! statement e%ecutes success"ully& S#L#$! * +,-. )ob'grades/

1.

!here are "our coding errors in this statement. $an you identi"y them2 S#L#$! sal % 12 +,-. employee'id( last'name *334*L S*L*,5 employees/

6. Show the structure o" the D#P*,!.#3!S table. Select all data "rom the D#P*,!.#3!S table. 7. Show the structure o" the #.PL-5##S table. $reate a 8uery to display the last name( )ob code( hire date( and employee number "or each employee( with employee number appearing "irst. Provide an alias S!*,!D*!# "or the 9I,#'D*!# column. Save your SQL statement to a "ile named lab1'7.s8l. :. ;. ,un your 8uery in the "ile lab1'7.s8l. $reate a 8uery to display uni8ue )ob codes "rom the #.PL-5##S table.

I" you have time( complete the "ollowing e%ercises& 1<. $opy the statement "rom lab1'7.s8l into the iSQL*Plus #dit window. 3ame the column headings #mp =( #mployee( >ob( and 9ire Date( respectively. ,un your 8uery again. 11. Display the last name concatenated with the )ob ID( separated by a comma and space( and name the column #mployee and !itle. I" you want an e%tra challenge( complete the "ollowing e%ercise& 12. $reate a 8uery to display all the data "rom the #.PL-5##S table. Separate each column by a comma. 3ame the column !9#'-4!P4!. Practice 2 1. $reate a 8uery to display the last name and salary o" employees earning more than ?12(<<<. Place your SQL statement in a te%t "ile named lab2'1.s8l. ,un your 8uery. 2. $reate a 8uery to display the employee last name and department number "or employee number 176. . .odi"y lab2'1.s8l to display the last name and salary "or all employees whose salary is not in the range o" ?1(<<< and ?12(<<<. Place your SQL statement in a te%t "ile named lab2' .s8l.

0. Display the employee last name( )ob ID( and start date o" employees hired between +ebruary 2<( 1;;:( and .ay 1( 1;;:. -rder the 8uery in ascending order by start date. 1. Display the last name and department number o" all employees in departments 2< and 1< in alphabetical order by name. 6. .odi"y lab2' .s8l to list the last name and salary o" employees who earn between ?1(<<< and ?12(<<<( and are in department 2< or 1<. Label the columns #mployee and .onthly Salary( respectively. ,esave lab2' .s8l as lab2'6.s8l. ,un the statement in lab2'6.s8l. 7. :. Display the last name and hire date o" every employee who was hired in 1;;0. Display the last name and )ob title o" all employees who do not have a manager.

;. Display the last name( salary( and commission "or all employees who earn commissions. Sort data in descending order o" salary and commissions. I" you have time( complete the "ollowing e%ercises. 1<. 11. Display the last names o" all employees where the third letter o" the name is an a. Display the last name o" all employees who have an a and an e in their last name.

I" you want an e%tra challenge( complete the "ollowing e%ercises 12. Display the last name( )ob( and salary "or all employees whose )ob is sales representative or stoc@ cler@ and whose salary is not e8ual to ?2(1<<( ? (1<<( or ?7(<<<. 1 . .odi"y lab2'6.s8l to display the last name( salary( and commission "or all employees whose commission amount is 2<A. ,esave lab2'6.s8l as lab2'1 .s8l. ,erun the statement in lab2'1 .s8l. . Practice 1. Brite a 8uery to display the current date. Label the column Date.

2. +or each employee( display the employee number( last'name( salary( and salary increased by 11A and e%pressed as a whole number. Label the column 3ew Salary. Place your SQL statement in a te%t "ile named lab '2.s8l. . ,un your 8uery in the "ile lab '2.s8l.

0. .odi"y your 8uery lab '2.s8l to add a column that subtracts the old salary "rom the new salary. Label the column Increase. Save the contents o" the "ile as lab '0.s8l. ,un the revised 8uery. 1. Brite a 8uery that displays the employeeCs last names with the "irst letter capitaliDed and all other letters lowercase and the length o" the name "or all employees whose name starts with >( *( or .. Eive each column an appropriate label. Sort the results by the employeesC last names. select initcapFlast'nameG( lengthFlast'nameG "rom employees where last'name li@e H>AH or last'name li@e H*AH or last'name li@e H.AH order by last'name 6. +or each employee( display the employeeCs last name( and calculate the number o" months between today and the date the employee was hired. Label the column .-3!9S'B-,I#D. -rder your results by the number o" months employed. ,ound the number o" months up to the closest whole number.

select last'name( roundFmonths'betweenFsysdate(hire'dateGG as J.onths'Bor@edJ "rom employees order by roundFmonths'betweenFsysdate(hire'dateGG 3ote& 5our results will di""er. 7. Brite a 8uery that produces the "ollowing "or each employee& Kemployee last nameL earns KsalaryL monthly but wants K times salaryL. Label the column Dream Salaries. select last'nameMMHearnsHMMsalaryMMHmonthly but wantHMMFsalary* G as JDream SalariesJ "rom employees I" you have time( complete the "ollowing e%ercises& :. $reate a 8uery to display the last name and salary "or all employees. +ormat the salary to be 11 characters long( le"tNpadded with ?. Label the column S*L*,5. ;. similar Display each employeeCs last name( hire date( and salary review date( which is the "irst .onday a"ter si% months o" service. Label the column ,#OI#B. +ormat the dates to appear in the "ormat to P.onday( the !hirtyN+irst o" >uly( 2<<<.Q select last'name(hire'date( salary( to'charFne%t'dayFhire'date(H.ondayHG(HDay JtheJ ddspth Jo"J .onth yyyyHGas JSalary ,eview DateJ "rom employees 1<. Display the last name( hire date( and day o" the wee@ on which the employee started. Label the column D*5. -rder the results by the day o" the wee@ starting with .onday. select last'name(hire'date(to'charFhire'date(HDyHG as JDayJ "rom employees order by to'charFhire'dateN1(HDHG I" you want an e%tra challenge( complete the "ollowing e%ercises& 11. $reate a 8uery that displays the employeesC last names and commission amounts. I" an employee does not earn commission( put P3o $ommission.Q Label the column $-... 12. $reate a 8uery that displays the employeesC last names and indicates the amounts o" their annual salaries with asteris@s. #ach asteris@ signi"ies a R Sort the data in descending order o" salary. Label the column #.PL-5##S'*3D'!9#I,'S*L*,I#S. 1 . 4sing the D#$-D# "unction( write a 8uery that displays the grade o" all employees based on the value o" the column >-S'ID( as per the "ollowing data& >-S E,*D# *D'P,#S S!'.*3 I!'P,-E S*',#P S!'$L#,I 3one o" the above 10. * S $ D # <

,ewrite the statement in the preceding 8uestion using the $*S# synta%.

Practice 0

1. Brite a 8uery to display the last name( department number( and department name "or all employees. 2. $reate a uni8ue listing o" all )obs that are in department :<. Include the location o" the department in the output. . Brite a 8uery to display the employee last name( department name( location ID( and city o" all employees who earn a commission. 0. Display the employee last name and department name "or all employees who have an a FlowercaseG in their last names. Place your SQL statement in a te%t "ile named lab0'0.s8l. 1. Brite a 8uery to display the last name( )ob( department number( and department name "or all employees who wor@ in !oronto. 6. Display the employee last name and employee number along with their managerCs last name and manager number. Label the columns #mployee( #mp=( .anager( and .gr=( respectively. Place your SQL statement in a te%t "ile named lab0'6.s8l. 7. .odi"y lab0'6.s8l to display all employees including Iing( who has no manager. Place your SQL statement in a te%t "ile named lab0'7.s8l. ,un the 8uery in lab0'7.s8l I" you have time( complete the "ollowing e%ercises. :. $reate a 8uery that displays employee last names( department numbers( and all the employees who wor@ in the same department as a given employee. Eive each column an appropriate label. ;. Show the structure o" the >-S'E,*D#S table. $reate a 8uery that displays the name( )ob( department name( salary( and grade "or all employees. I" you want an e%tra challenge( complete the "ollowing e%ercises& 1<. $reate a 8uery to display the name and hire date o" any employee hired a"ter employee Davies. 11. Display the names and hire dates "or all employees who were hired be"ore their managers( along with their managerCs names and hire dates. Label the columns #mployee( #mp 9ired( .anager( and .gr 9ired( respectively. Practice 1 Determine the validity o" the "ollowing three statements. $ircle either !rue or +alse. 1. 2. . Eroup "unctions wor@ across many rows to produce one result. Eroup "unctions include nulls in calculations. !he B9#,# clause restricts rows prior to inclusion in a group calculation.

0. Display the highest( lowest( sum( and average salary o" all employees. Label the columns .a%imum( .inimum( Sum( and *verage( respectively. ,ound your results to the nearest whole number. Place your SQL statement in a te%t "ile named lab1'6.s8l. 1. .odi"y the 8uery in lab1'0.s8l to display the minimum( ma%imum( sum( and average salary "or each )ob type. ,esave lab1'6.s8l to lab1'0.s8l. ,un the statement in lab1'1.s8l. 6. Brite a 8uery to display the number o" people with the same )ob.

7. Determine the number o" managers without listing them. Label the column 3umber o" .anagers. 9int& 4se the .*3*E#,'ID column to determine the number o" managers. :. Brite a 8uery that displays the di""erence between the highest and lowest salaries. Label the column DI++#,#3$#. I" you have time( complete the "ollowing e%ercises. ;. Display the manager number and the salary o" the lowest paid employee "or that manager. #%clude anyone whose manager is not @nown. #%clude any groups where the minimum salary is ?6(<<< or less. Sort the output in descending order o" salary. 1<. Brite a 8uery to display each departmentCs name( location( number o" employees( and the average salary "or all employees in that department. Label the columns 3ame( Location( 3umber o" People( and Salary( respectively. ,ound the average salary to two decimal places. I" you want an e%tra challenge( complete the "ollowing e%ercises& 11. $reate a 8uery that will display the total number o" employees and( o" that total( the number o" employees hired in 1;;1( 1;;6( 1;;7( and 1;;:. $reate appropriate column headings. 12. $reate a matri% 8uery to display the )ob( the salary "or that )ob based on department number( and the total salary "or that )ob( "or departments 2<( 1<( :<( and ;<( giving each column an appropriate heading. Practice 6 1. Brite a 8uery to display the last name and hire date o" any employee in the same department as Tlot@ey. #%clude Tlot@ey. 2. $reate a 8uery to display the employee numbers and last names o" all employees who earn more than the average salary. Sort the results in ascending order o" salary. . Brite a 8uery that displays the employee numbers and last names o" all employees who wor@ in a department with any employee whose last name contains a u. Place your SQL statement in a te%t "ile named lab6' .s8l. ,un your 8uery. 0. Display the last name( department number( and )ob ID o" all employees whose department location ID is 17<<. 1. Display the last name and salary o" every employee who reports to Iing.

6. Display the department number( last name( and )ob ID "or every employee in the #%ecutive department. I" you have time( complete the "ollowing e%ercises& 7. .odi"y the 8uery in lab6' .s8l to display the employee numbers( last names( and salaries o" all employees who earn more than the average salary and who wor@ in a department with any employee with a u in their name. ,esave lab6' .s8l to lab6'7.s8l. ,un the statement in lab6'7.s8l. Practice 7 Determine whether the "ollowing statements are true or "alse& 1. !he "ollowing statement is correct& D#+I3# U p'val V 1<< 2. !he D#+I3# command is a SQL command.

. Brite a script to display employees who started between a separated by a space and comma( "ile( use the D#+I3# command to the script "iles as lab7' a.s8l

the employee last name( )ob( and hire date "or all given range. $oncatenate the name and )ob together( and label the column #mployees. In a separate SQL script provide the two ranges. 4se the "ormat ..RDDR5555. Save and lab7' b.s8l.

0. Brite a script to display the employee last name( )ob( and department name "or a given location. !he search condition should allow "or caseNinsensitive searches o" the department location. Save the script "ile as lab7'0.s8l. 1. .odi"y the code in lab7'0.s8l to create a report containing the department name( employee last name( hire date( salary( and each employeeCs annual salary "or all employees in a given location. Label the columns D#P*,!.#3! 3*.#( #.PL-5## 3*.#( S!*,! D*!#( S*L*,5( and *334*L S*L*,5( placing the labels on multiple lines. ,esave the script as lab7'1.s8l and e%ecute the commands in the script. Practice : Insert data into the .5'#.PL-5## table. 1. ,un the statement in the lab:'1.s8l script to build the .5'#.PL-5## table that will be used "or the lab. 2. Describe the structure o" the .5'#.PL-5## table to identi"y the column names.

. *dd the "irst row o" data to the .5'#.PL-5## table "rom the "ollowing sample data. Do not list the columns in the I3S#,! clause. ID 1 2 0 1 L*S!'3*.# Patel Denise Siri 3ewman ,epolum +I,S!'3*.# ,alph Setty Sen $hed *nthony 4S#,ID rpatel bdenise bbiri cnewman arepolum S*L*,5 :;1 :0< 11<< 71< 111<

0. Populate the .5'#.PL-5## table with the second row o" sample data "rom the preceding list. !his time( list the columns e%plicitly in the I3S#,! clause. 1. $on"irm your addition to the table.

6. Brite an insert statement in a te%t "ile named loademp.s8l to load rows into the .5'#.PL-5## table. $oncatenate the "irst letter o" the "irst name and the "irst seven characters o" the last name to produce the userid. 7. Populate the table with the ne%t two rows o" sample data by running the insert statement in the script that you created. :. ;. $on"irm your additions to the table. .a@e the data additions permanent.

4pdate and delete data in the .5'#.PL-5## table. 1<. 11. 12. $hange the last name o" employee to Dre%ler.

$hange the salary to 1<<< "or all employees with a salary less than ;<<. Oeri"y your changes to the table.

1 . 10. 11.

Delete Setty Dancs "rom the .5'#.PL-5## table. $on"irm your changes to the table. $ommit all pending changes.

$ontrol data transaction to the .5'#.PL-5## table. 16. Populate the table with the last row o" sample data by modi"ying the statements in the script that you created in step 6. ,un the statements in the script. 17. 1:. 1;. 2<. $on"irm your addition to the table. .ar@ an intermediate point in the processing o" the transaction. #mpty the entire table. $on"irm that the table is empty.

21. Discard the most recent D#L#!# operation without discarding the earlier I3S#,! operation. 22. 2 . $on"irm that the new row is still intact. .a@e the data addition permanent.

Practice ; 1. $reate the D#P! table based on the "ollowing table instance chart. Place the synta% in a script called lab;'1.s8l( then e%ecute the statement in the script to create the table. $on"irm that the table is created. $olumn 3ame Iey !ype 3ullsR4ni8ue PI !able PI $olumn Data !ype Length ID 3*.#

34.S#, 7

O*,$9*,2 21

2. Populate the D#P! table with data "rom the D#P*,!.#3!S table. Include only columns that you need. . $reate the #.P table based on the "ollowing table instance chart. Place the synta% in a script called lab;' .s8l( and then e%ecute the statement in the script to create the table. $on"irm that the table is created. $olumn 3ame Iey !ype 3ullsR4ni8ue PI !able PI $olumn Data !ype Length ID L*S!'3*.# +I,S!'3*.# D#P!'ID

34.S#, 7

O*,$9*,2 21

O*,$9*,2 21

34.S#, 7

0. .odi"y the #.P table to allow "or longer employee last names. $on"irm your modi"ication. 1. $on"irm that both the D#P! and #.P tables are stored in the data dictionary. F9int& 4S#,'!*SL#SG

6. $reate the #.PL-5##S2 table based on the structure o" the #.PL-5##S table. Include only the #.PL-5##'ID( +I,S!'3*.#( L*S!'3*.#( S*L*,5( and D#P*,!.#3!'ID columns. 3ame the columns in your new table ID( +I,S!'3*.#( L*S!'3*.#( S*L*,5 ( and D#P!'ID( respectively. 7. :. Drop the #.P table. ,ename the #.PL-5##S2 table to #.P.

;. *dd a comment to the D#P! and #.P table de"initions describing the tables. $on"irm your additions in the data dictionary. 1<. Drop the +I,S!'3*.# column "rom the #.P table. $on"irm your modi"ication by chec@ing the description o" the table. 11. In the #.P table( mar@ the D#P!'ID column in the #.P table as 434S#D. $on"irm your modi"ication by chec@ing the description o" the table. 12. Drop all the 434S#D columns "rom the #.P table. $on"irm your modi"ication by chec@ing the description o" the table. Practice 1< 1. *dd a tableNlevel P,I.*,5 I#5 constraint to the #.P table on the ID column. !he constraint should be named at creation. 3ame the constraint my'emp'id'p@ 2. $reate a P,I.*,5 I#5 constraint to the D#P! table using the ID column. !he constraint should be named at creation. 3ame the constraint my'dept'id'p@. . *dd a column D#P!'ID to the #.P table. *dd a "oreign @ey re"erence on the #.P table that ensures that the employee is not assigned to a none%istent department. 3ame the constraint my'emp'dept'id'"@. 0. $on"irm that the constraints were added by 8uerying the 4S#,'$-3S!,*I3!S view. 3ote the types and names o" the constraints. Save your statement te%t in a "ile called lab1<'0.s8l. 1. Display the ob)ect names and types "rom the 4S#,'-S>#$!S data dictionary view "or the #.P and D#P! tables. 3otice that the new tables and a new inde% were created. 6. .odi"y the #.P table. *dd a $-..ISSI-3 column o" 34.S#, data type( precision 2( scale 2. *dd a constraint to the commission column that ensures that a commission value is greater than Dero. Practice 11 1. $reate a view called #.PL-5##S'O4 based on the employee numbers( employee names( and department numbers "rom the #.PL-5##S table. $hange the heading "or the employee name to #.PL-5##. 2. . Display the contents o" the #.PL-5##S'O4 view.

Select the view name and te%t "rom the 4S#,'OI#BS data dictionary view. 3ote& *nother view already e%ists. !he #.P'D#!*ILS'OI#B was created as part o" your schema. 3ote& !o see more contents o" a L-3E column( use the iSQL*Plus command S#! L-3E n( where n is the value o" the number o" characters o" the L-3E column that you want to see. 0. 4sing your #.PL-5##S'O4 view( enter a 8uery to display all employee names and department numbers. 1. $reate a view named D#P!1< that contains the employee numbers( employee last names(

and department numbers "or all employees in department 1<. Label the view columns #.P3-( #.PL-5##( and D#P!3-. Do not allow an employee to be reassigned to another department through the view. 6. 7. Display the structure and contents o" the D#P!1< view. *ttempt to reassign .atos to department :<.

I" you have time( complete the "ollowing e%ercise& :. $reate a view called S*L*,5'O4 based on the employee last names( department names( salaries( and salary grades "or all employees. 4se the #.PL-5##S( D#P*,!.#3!S( and >-S'E,*D#S tables. Label the columns #mployee( Department( Salary( and Erade( respectively. Practice 12 1. $reate a se8uence to be used with the primary @ey column o" the D#P! table. !he se8uence should start at 2<< and have a ma%imum value o" 1<<<. 9ave your se8uence increment by ten numbers. 3ame the se8uence D#P!'ID'S#Q. 2. Brite a 8uery in a script to display the "ollowing in"ormation about your se8uences& se8uence name( ma%imum value( increment siDe( and last number. 3ame the script lab12'2.s8l. ,un the statement in your script. . Brite a script to insert two rows into the D#P! table. 3ame your script lab12' .s8l. Se sure to use the se8uence that you created "or the ID column. *dd two departments named #ducation and *dministration. $on"irm your additions. ,un the commands in your script. 0. $reate a nonuni8ue inde% on the "oreign @ey column FD#P!'IDG in the #.P table.

1. Display the inde%es and uni8ueness that e%ist in the data dictionary "or the #.P table. Save the statement into a script named lab12'1.s8l. Practice 1 1. Bhat privilege should a user be given to log on to the -racle Server2 Is this a system or an ob)ect privilege2 2. . Bhat privilege should a user be given to create tables2 I" you create a table( who can pass along privileges to other users on your table2

0. 5ou are the DS*. 5ou are creating many users who re8uire the same system privileges. Bhat should you use to ma@e your )ob easier2 1. Bhat command do you use to change your password2

6. Erant another user access to your D#P*,!.#3!S table. 9ave the user grant you 8uery access to his or her D#P*,!.#3!S table. 7. Query all the rows in your D#P*,!.#3!S table.

:. *dd a new row to your D#P*,!.#3!S table. !eam 1 should add #ducation as department number 1<<. !eam 2 should add 9uman ,esources department number 11<. Query the other teamCs table. ;. 1<. synonym. $reate a synonym "or the other teamCs D#P*,!.#3!S table. Query all the rows in the other teamCs D#P*,!.#3!S table by using your

11. Query the 4S#,'!*SL#S data dictionary to see in"ormation about the tables that you own. 12. Query the *LL'!*SL#S data dictionary view to see in"ormation about all the tables that you can access. #%clude tables that you own. 1 . ,evo@e the S#L#$! privilege "rom the other team.

,emove the row you inserted into the D#P*,!.#3!S table in step : and save the changes. Practice 10 1. $reate the tables based on the "ollowing table instance charts. $hoose the appropriate data types and be sure to add integrity constraints. a. !able name& .#.S#, $olumn 3ame .#.S#,'ID L*S!'3*.# +I,S!'3*.# *DD,#SS Iey !ype PI 3ullsR4ni8ue 33 R 4 33 De"ault Oalue Data !ype Length b. 34.S#, 1< O*,$9*,2 21 O*,$9*,2 21 $I!5 P9-3# >-I3'D*!#

System Date O*,$9*,2 O*,$9*,2 O*,$9*,2 D*!# 1<< < 11

!able name& !I!L# D#S$,IP!I-3 33 E( PE( ,( 3$17( 3, O*,$9*,2 0 2< D,*.*( $-.#D5( *$!I-3( $9ILD( S$I+I( D-$4.#3!*,5 O*,$9*,2 ,*!I3E $*!#E-,5 ,#L#*S#'D*!#

$olumn 3ame !I!L#'ID !I!L# Iey !ype PI 3ullsR4ni8ue 33 R 4 33 $hec@

Data !ype Length c.

34.S#, 1<

O*,$9*,2 O*,$9*,2 6< 0<<

D*!#

!able name& !I!L#'$-P5 $-P5'ID PI 33 R 4 !I!L#'ID PI( +I 33 R4 S!*!4S 33 *O*IL*SL#( D#S!,-5#D( ,#3!#D( ,#S#,O#D O*,$9*,2 11

$olumn 3ame Iey !ype 3ullsR4ni8ue $hec@

+I ,el !able +I ,el $ol Data !ype Length d.

34.S#, 1<

!I!L# !I!L#'ID 34.S#, 1<

!able name& ,#3!*L S--I'D*!# .#.S#,'ID $-P5'ID PI( +I2 System Date X 2 days *$!',#! 'D*!# #WP',#! 'D*!# !I!L#'ID PI( +I

$olumn 3ame

Iey !ype PI PI( +I1 De"ault Oalue System Date

10

+I ,el !able +I ,el $ol Data !ype Length e.

D*!#

.#.S#, .#.S#,'ID 34.S#, 1<

!I!L#'$-P5 $-P5'ID 34.S#, 1<

D*!#

D*!#

!I!L#'$-P5 !I!L#'ID 34.S#, 1<

!able name& ,#S#,O*!I-3 ,#S'D*!# PI 33 R 4 D*!# .#.S#,'ID PI( +I1 33 R 4 .#.S#, .#.S#,'ID 34.S#, 1< !I!L#'ID PI( +I2 33 !I!L# !I!L#'ID 34.S#, 1<

$olumn 3ame Iey !ype 3ullR4ni8ue +I ,el !able +I ,el $ol Data !ype Length

2. Oeri"y that the tables and constraints were created properly by chec@ing the data dictionary. . $reate se8uences to uni8uely identi"y each row in the .#.S#, table and the !I!L# table. a. .ember number "or the .#.S#, table& start with 1<1/ do not allow caching o" the values. 3ame the se8uence .#.S#,'ID'S#Q. b. !itle number "or the !I!L# table& start with ;2/ no caching. 3ame the se8uence !I!L#'ID'S#Q. c. 0. Oeri"y the e%istence o" the se8uences in the data dictionary.

*dd data to the tables. $reate a script "or each set o" data to add. a. *dd movie titles to the !I!L# table. Brite a script to enter the movie in"ormation. Save the statements in a script named lab10'0a.s8l. 4se the se8uences to uni8uely identi"y each title. #nter the release dates in the DDN.-3N5555 "ormat. ,emember that single 8uotation mar@s in a character "ield must be specially handled. Oeri"y your additions. !itle Billie and $hristmas !oo *lien *gain Description ,ating E $ategory ,elease Date $9ILD <1N-$!N1;;1

*ll o" BillieHHs "riends ma@e a $hristmas list "or Santa( but Billie has yet to add his own wish list. 5et another installment o" science "iction history. $an the heroine save the planet "rom the alien li"e "orm2 * meteor crashes near a small *merican town and unleashes carnivorous goo in this classic. Bith a little luc@ and a lot ingenuity( a teenager s@ips school "or a day in 3ew 5or@.

S$I+I

1;N.*5N1;;1

!he Elob

3,

S$I+I

12N*4EN1;;1

.y Day -""

PE

$-.#D5

12N>4LN1;;1

.iracles on * si%NyearNold has doubts

PE

D,*.*

12NS#PN1;;1

11

Ice

about Santa $laus( but she discovers that miracles really do e%ist. *"ter discovering a cache o" drugs( a young couple "ind themselves pitted against a vicious gang. 3, *$!I-3 <1N>43N1;;1

Soda Eang

b. *dd data to the .#.S#, table. Place the insert statements in a script named lab10'0b.s8l. #%ecute commands in the script. Se sure to use the se8uence to add the member numbers. +irst' 3ame $armen LaDoris .idori .ar@ *udry .olly Last'3ame Oelas8ueD 3gao 3agayama Quic@N!o'See ,opeburn 4rguhart *ddress 2: $ity Phone 2<6N:;;N6666

Iing Street Seattle

1 .odrany

Sratislava 1:6N 11N:::2 210N:12N1760 6 N11;N7777 01N11;N:7 01:N102N;;::

6: Oia $entrale Sao Paulo 6;21 Iing Bay :6 $hu Street < 1 Laurier Lagos 9ong Iong Qubec

c. *dd the "ollowing movie copies in the !I!L#'$-P5 table& 3ote& 9ave the !I!L#'ID numbers available "or this e%ercise. !itle Billy and $hristmas !oo *lien *gain !he Elob .y Day -"" .iracles -n Ice Soda Eang $opy'Id 1 1 2 1 1 2 1 1 Status *O*IL*SL# *O*IL*SL# ,#3!#D *O*IL*SL# *O*IL*SL# *O*IL*SL# ,#3!#D *O*IL*SL# *O*IL*SL#

d. *dd the "ollowing rentals to the ,#3!*L table& 3ote& !itle number may be di""erent depending on se8uence number. !itle' Id ;2 ; ;1 ;7 $opy' .ember' Soo@'Date Id Id 1 2 1 1<1 1<1 1<2 1<6 days ago 1 day ago 2 days ago 0 days ago #%p',et'Date *ct',et'Date 1 day ago 2days ago 1 day "rom now !oday 2 days ago 2 days ago

1. $reate a view named !I!L#'*O*IL to show the movie titles and the availability o" each copy and its e%pected return date i" rented. Query all rows "rom the view. -rder the results by title. 6. .a@e changes to data in the tables.

12

a. *dd a new title. !he movie is PInterstellar Bars(Q which is rated PE and classi"ied as a science "iction movie. !he release date is <7N>4LN77. !he description is P+uturistic interstellar action movie. $an the rebels save the humans "rom the evil empire2Q Se sure to add a title copy record "or two copies. b. #nter two reservations. -ne reservation is "or $armen Oelas8ueD( who wants to rent PInterstellar Bars.Q !he other is "or .ar@ Quic@NtoNSee( who wants to rent PSoda Eang.Q c. $ustomer $armen Oelas8ueD rents the movie PInterstellar Bars(Q copy 1. ,emove her reservation "or the movie. ,ecord the in"ormation about the rental. *llow the de"ault value "or the e%pected return date to be used. Oeri"y that the rental was recorded by using the view you created. 7. .a@e a modi"ication to one o" the tables.

a. *dd a P,I$# column to the !I!L# table to record the purchase price o" the video. !he column should have a total length o" eight digits and two decimal places. Oeri"y your modi"ications. b. $reate a script named lab10'7b.s8l that contains update statements that update each video with a price according to the "ollowing list. ,un the commands in the script. 3ote& 9ave the !I!L#'ID numbers available "or this e%ercise. !itle Bhilie and $hristmas !oo *lien *gain !he Elob .y Day -"" .iracles on Ice Soda Eang Interstellar Bars c. Price 21 1 1 1 < 1 2;

#nsure that in the "uture all titles contain a price value. Oeri"y the constraint.

:. $reate a report titled $ustomer 9istory ,eport. !his report contains each customerHs history o" renting videos. Se sure to include the customer name( movie rented( dates o" the rental( and duration o" rentals. !otal the number o" rentals "or all customers "or the reporting period. Save the commands that generate the report in a script "ile named lab10':.s8l. Practice 11 1. List the department IDs "or departments that do not contain the )ob ID S!'$L#,I( using S#! operators. 2. Display the country ID and the name o" the countries that have no departments located in them( using S#! operators. . Produce a list o" )obs "or departments 1<( 1<( and 2<( in that order. Display )ob ID and department ID( using S#! operators. 0. List the employee IDs and )ob IDs o" those employees who currently have the )ob title that they held be"ore beginning their tenure with the company. 1. Brite a compound 8uery that lists the "ollowing& Last names and department ID o" all the employees "rom the #.PL-5##S table( regardless o" whether or not they belong to any department Department ID and

13

department name o" all the departments "rom the D#P*,!.#3!S table( regardless o" whether or not they have employees wor@ing in them Practice 16 1. *lter the session to set the 3LS'D*!#'+-,.*! to DDN.-3N5555 9920&.I&SS.

2. a. Brite 8ueries to display the time Done o""sets F!T'-++S#!G "or the "ollowing time Dones. 4SRPaci"icN3ew Singapore #gypt b. *lter the session to set the !I.#'T-3# parameter value to the time Done o""set o" 4SRPaci"icN3ew. c. session. Display the $4,,#3!'D*!#( $4,,#3!'!I.#S!*.P( and L-$*L!I.#S!*.P "or this 3ote& !he output might be di""erent based on the date when the command is e%ecuted. d. *lter the session to set the !I.#'T-3# parameter value to o""set o" Singapore. e. the time Done

Display the $4,,#3!'D*!#( $4,,#3!'!I.#S!*.P( L-$*L!I.#S!*.P "or this session. 3ote& !he output might be di""erent( based on the date when the command is e%ecuted. . Brite a 8uery to display the DS!I.#T-3# and S#SSI-3!I.#T-3#.

0. Brite a 8uery to e%tract the 5#*, "rom 9I,#'D*!# column o" the #.PL-5##S table "or those employees who wor@ in department :<. *lter the session to set the 3LS'D*!#'+-,.*! to Practice 17 1. Brite a 8uery to display the "ollowing "or those employees whose manager ID is less than 12<& .anager ID >ob ID and total salary "or every )ob ID "or employees who report to the same manager !otal salary o" those managers !otal salary o" those managers( irrespective o" the )ob IDs 2. -bserve the output "rom 8uestion 1. Brite a 8uery using the E,-4PI3E "unction to determine whether the 34LL values in the columns corresponding to the E,-4P S5 e%pressions are caused by the ,-LL4P operation. . Brite a 8uery to display the "ollowing "or those employees whose manager ID is less than 12< & .anager ID >ob and total salaries "or every )ob "or employees who report to the same manager !otal salary o" those managers $rossNtabulation values to display the total salary "or every )ob( irrespective o" the manager !otal salary irrespective o" all )ob titles 0. -bserve the output "rom 8uestion . Brite a 8uery using the E,-4PI3E "unction to determine whether the 34LL values in the columns corresponding to the E,-4P S5 e%pressions are caused by the $4S# operation. DDN.-3N5555.

14

1.

4sing E,-4PI3E S#!S( write a 8uery to display the "ollowing groupings & department'id( manager'id( )ob'id department'id( )ob'id .anager'id( )ob'id !he 8uery should calculate the sum o" the salaries "or each o" these groups.

Practice 1: 1. Brite a 8uery to display the last name( department number( and salary o" any employee whose department number and salary both match the department number and salary o" any employee who earns a commission. 2. Display the last name( department name( and salary o" any employee whose salary and commission match the salary and commission o" any employee located in location ID17<<. . $reate a 8uery to display the last name( hire date( and salary "or all employees who have the same salary and commission as Iochhar. 3ote& Do not display Iochhar in the result set. 0. $reate a 8uery to display the employees who earn a salary that is higher than the salary o" all o" the sales managers F>-S'ID V HS*'.*3HG. Sort the results on salary "rom highest to lowest. 1. Display the details o" the employee ID( last name( and department ID employees who live in cities whose name begins with !. o" those

6. Brite a 8uery to "ind all employees who earn more than the average salary in their departments. Display last name( salary( department ID( and the average salary "or the department. Sort by average salary. 4se aliases "or the columns retrieved by the 8uery as shown in the sample output. 7. +ind all employees who are not supervisors. a. +irst do this by using the 3-! #WIS!S operator. b. $an this be done by using the 3-! I3 operator2 9ow( or why not2 :. Brite a 8uery to display the last names o" the employees who earn less than the average salary in their departments. ;. Brite a 8uery to display the last names o" employees who have one or more cowor@ers in their departments with later hire dates but higher salaries. 1<. Brite a 8uery to display the employee ID( last names( and department names o" all employees. 3ote& 4se a scalar sub8uery to retrieve the department name in the 11. Brite a 8uery to display the department names o" those departments whose total salary cost is above oneNeighth F1R:G o" the total salary cost o" the whole company. 4se the BI!9 clause to write this 8uery. 3ame the 8uery S4..*,5. Practice 1; 1. Loo@ at the "ollowing outputs. *re these outputs the result o" a hierarchical 8uery2 #%plain why or why not. #%hibit 1& #%hibit 2& #%hibit &

15

2. Produce a report showing an organiDation chart "or .ourgosCs department. Print last names( salaries( and department IDs. . $reate a report that shows the hierarchy o" the managers "or the employee LorentD. Display his immediate manager "irst. 0. $reate an indented report showing the management hierarchy starting "rom the employee whose L*S!'3*.# is Iochhar. Print the employeeCs last name( manager ID( and department ID. Eive alias names to the columns as shown in the sample output. I" you have time( complete the "ollowing e%ercises& 1. Produce a company organiDation chart that shows the management hierarchy. Start with the person at the top level( e%clude all people with a )ob ID o" I!'P,-E( and e%clude De 9aan and those employees who report to De 9aan. Practice 2< 1. ,un the cre'sal'history.s8l script in the lab "older to create the S*L'9IS!-,5 table. 2. Display the structure o" the S*L'9IS!-,5 table.

. ,un the cre'mgr'history.s8l script in the lab "older to create the .E,'9IS!-,5 table. 0. Display the structure o" the .E,'9IS!-,5 table.

1. ,un the cre'special'sal.s8l script in the lab "older to create the SP#$I*L'S*L table. 6. Display the structure o" the SP#$I*L'S*L table.

7. a. Brite a 8uery to do the "ollowing& ,etrieve the details o" the employee ID( hire date( salary( and manager ID o" those employees whose employee ID is less than 121 "rom the #.PL-5##S table. I" the salary is more than ?2<(<<<( insert the details o" employee ID and salary into the SP#$I*L'S*L table. Insert the details o" the employee ID( hire date( and salary into the S*L'9IS!-,5 table. Insert the details o" the employee ID( manager ID( and S5SD*!# into the .E,'9IS!-,5 table. b. Display the records "rom the SP#$I*L'S*L table. c. Display the records "rom the S*L'9IS!-,5 table. d. Display the records "rom the .E,'9IS!-,5 table. :. a. ,un the cre'sales'source'data.s8l script in the lab "older to create the S*L#S'S-4,$#'D*!* table. b. ,un the ins'sales'source'data.s8l script in the lab "older to insert records into the S*L#S'S-4,$#'D*!* table. c. Display the structure o" the S*L#S'S-4,$#'D*!* table. d. Display the records "rom the S*L#S'S-4,$#'D*!* table. e. ,un the cre'sales'in"o.s8l script in the lab "older to create the S*L#S'I3+table.

16

". Display the structure o" the S*L#S'I3+- table. g. Brite a 8uery to do the "ollowing& ,etrieve the details o" the employee ID( wee@ ID( sales on .onday( sales on !uesday( sales on Bednesday( sales on !hursday( and sales on +riday "rom the S*L#S'S-4,$#'D*!* table. Suild a trans"ormation such that each record retrieved "rom the S*L#S'S-4,$#'D*!* table is converted into multiple records "or the S*L#S'I3+- table. 9int& 4se a pivoting I3S#,! statement. h. Display the records "rom the S*L#S'I3+- table. ;. a. $reate the D#P!'3*.#D'I3D#W table based on the "ollowing table instance chart. 3ame the inde% "or the P,I.*,5 I#5 column as D#P!'PI'IDW. $-L4.3 3ame Primary Iey Data !ype Length b. Deptno 5es 3umber 0 Dname O*,$9*,2 <

Query the 4S#,'I3D#W#S table to display the I3D#W'3*.# "or the D#P!'3*.#D'I3D#W table.

17

Potrebbero piacerti anche