Vous êtes sur la page 1sur 40

INSTITUTO TECNOLGICO DE APIZACO

Taller de Base de Datos

PROF. JOSE ANTONIO ZAMORA CRUZ

JAQUELINE CUAHTEPITZI BASTIDA

PRACTICAS 1 A 7
ORACLE SQL

22 MARZO - 2017
Contenido
PRACTICA 1......................................................................................................... 3
Pregunta 3....................................................................................................... 3
Pregunta 4....................................................................................................... 3
Pregunta 5....................................................................................................... 3
PREGUNTA 6..................................................................................................... 4
Pregunta 7....................................................................................................... 4
Pregunta 9....................................................................................................... 5
Pregunta 10..................................................................................................... 5
Pregunta 11..................................................................................................... 6
Pregunta 12..................................................................................................... 6
PRACTICA # 2...................................................................................................... 7
UNO................................................................................................................. 7
DOS.................................................................................................................. 7
TRES................................................................................................................ 8
CUATRO............................................................................................................ 8
CINCO.............................................................................................................. 9
SEIS.................................................................................................................. 9
SIETE................................................................................................................ 9
OCHO............................................................................................................. 10
NUEVE............................................................................................................ 10
DIEZ............................................................................................................... 10
ONCE............................................................................................................. 11
DOCE............................................................................................................. 11
Practica 3.......................................................................................................... 13
Pregunta 1..................................................................................................... 13
Pregunta 2..................................................................................................... 13
Pregunta 3..................................................................................................... 14
Pregunta 4..................................................................................................... 14
Pregunta 5..................................................................................................... 15
Pregunta 6..................................................................................................... 15
Pregunta 7..................................................................................................... 16
Pregunta 8..................................................................................................... 17
Pregunta 9..................................................................................................... 18
Pregunta 10................................................................................................... 18
Pregunta 11................................................................................................... 19
Pregunta 12................................................................................................... 19
Pregunta 13................................................................................................... 20
Pregunta 14................................................................................................... 20
PRACTICA 4....................................................................................................... 21
PREGUNTA 1.................................................................................................. 21
PREGUNTA 2................................................................................................... 21
PREGUNTA 3................................................................................................... 22
PREGUNTA 4................................................................................................... 22
PREGUNTA 5................................................................................................... 23
PREGUNTA 6................................................................................................... 23
PREGUNTA 7................................................................................................... 24
PREGUNTA 8................................................................................................... 24
PREGUNTA 9................................................................................................... 24
PREGUNTA 10................................................................................................. 25
PREGUNTA 11................................................................................................. 26
PRACTICA # 5.................................................................................................... 27
PREGUNTA 1................................................................................................... 27
PREGUNTA 2................................................................................................... 27
PREGUNTA 3................................................................................................... 27
PREGUNTA 4................................................................................................... 27
PREGUNTA 5................................................................................................... 28
PREGUNTA 6................................................................................................... 28
PREGUNTA 7................................................................................................... 29
PREGUNTA 8................................................................................................... 29
PREGUNTA 9................................................................................................... 30
PREGUNTA 10................................................................................................. 30
PREGUNTA 11................................................................................................. 31
PREGUNTA 12................................................................................................. 31
PRACTICA 6....................................................................................................... 32
PREGUNTA 1................................................................................................... 32
PREGUNTA 2................................................................................................... 32
PREGUNTA 3................................................................................................... 33
PREGUNTA 4................................................................................................... 33
PREGUNTA 5................................................................................................... 34
PREGUNTA 6................................................................................................... 34
PREGUNTA 7................................................................................................... 34
PRACTICA 7....................................................................................................... 35
Pregunta 1..................................................................................................... 35
Pregunta 2..................................................................................................... 35
Pregunta 3..................................................................................................... 35
Pregunta 4..................................................................................................... 35
PRACTICA 1
Pregunta 3
The following SELECT statement executes successfully:

SELECT last_name, job_id, salary AS Sal FROM


employees;

Pregunta 4
True/False
R= Falso, porque o existe la tabla job_grades;

Pregunta 5
True/False
There are four coding errors in this statement. Can you identify them?
SELECT employee_id, last_name
sal x 12 ANNUAL SALARY
FROM employees;
Es incorrecta porque sal x 12 se escribira sal * 12
ANNUAL SALARY se escribira ANNUAL_SALARY
adems no existe la tabla Annual Salary.
PREGUNTA 6
Show the structure of the DEPARTMENTS table. Select all data from

the table.

Pregunta 7
Muestra la estructura de la tabla EMPLOYEES. Crea una consulta para mostrar
last_name, job_code, hire_date, y employee_number para cada empleado, mostrando
employee_number al principio. Proporcione un alias STARTDATE para la columna
HIRE_DATE. Guarde su sentencia SQL en un archivo denominado lab1_7.sql
Pregunta 9
Cree una consulta para mostrar los cdigos unicos de la tabla EMPLOYEES.

Pregunta 10
1 Copie la sentencia de lab1_7.sql en la ventana de edicion de iSQL*Plus Edit.
Nombre los encabezados de las colunas Emp #, Employee, Job, y Hire Date,
respectivamente. Corra su consulta una vez mas.
Pregunta 11
Display the last name concatenated with the job ID, separated by a comma and
space, and name the column Employee and Title.

Pregunta 12
Create a query to display all the data from the EMPLOYEES table.
Separate each column by a comma. Name the column THE_OUTPUT.
PRACTICA 2
UNO
1. CREAR UNA CONSULTA QUE MUESTRE EL APELLIDO Y EL SUELDO
DE LOS EMPLEADOS QUE GANAN MS DE 12.000 DLARES.
COLOCAR LA INSTRUCCIN SQL EN UN ARCHIVO DE TEXTO
LLAMADO LAB2_1.SQL. EJECUTAR LA CONSULTA.

DOS
2. CREAR UNA CONSULTA PARA VER LOS APELLIDOS DEL EMPLEADO
Y EL NMERO DE DEPARTAMENTO PARA EL EMPLEADO NMERO
176.
TRES
3. MODIFICAR LAB2_1.SQL PARA MOSTRAR EL APELLIDO Y EL SALARIO
DE TODOS LOS EMPLEADOS CUYO SALARIO NO EST EN EL RANGO DE
$5.000 Y $12.000.
COLOCAR LA INSTRUCCIN SQL EN UN ARCHIVO DE TEXTO LLAMADO
LAB2_3.SQL.

CUATRO
4. MOSTRAR EL LTIMO EMPLEADO NOMBRE, ID DE TRABAJO Y LA
FECHA DE INICIO DE LOS EMPLEADOS CONTRATADOS ENTRE EL 20 DE
FEBRERO DE 1998, Y EL 1 DE MAYO DE 1998.

SOLICITAR LA CONSULTA EN ORDEN ASCENDENTE POR FECHA DE INICIO.


CINCO
5. MOSTRAR EL APELLIDO Y EL NMERO DE SERVICIO DE TODOS LOS
EMPLEADOS EN LOS DEPARTAMENTOS 20 Y 50 EN ORDEN ALFABTICO
POR EL NOMBRE.

SEIS
MODIFICAR LAB2_3.SQL PARA ENUMERAR LOS APELLIDOS Y EL SUELDO
DE LOS EMPLEADOS QUE GANAN ENTRE $5.000 Y $12.000, Y ESTN EN EL
DEPARTAMENTO DE 20 O 50. ETIQUETAR LAS COLUMNAS EMPLEADO Y
SALARIO MENSUAL, RESPECTIVAMENTE. VOLVER A GUARDAR
LAB2_3.SQL COMO LAB2_6.SQL. EJECUTAR LA INSTRUCCIN EN
LAB2_6.SQL.

SIETE
7. MOSTRAR EL APELLIDO Y FECHA DE CONTRATACIN DE CADA
EMPLEADO QUE FUE CONTRATADO EN 1994.
OCHO
8. MOSTRAR EL LTIMO NOMBRE Y TTULO DEL TRABAJO DE TODOS LOS
EMPLEADOS QUE NO TIENEN UN ADMINISTRADOR.

NUEVE
9. MOSTRAR EL LTIMO NOMBRE, SUELDO, Y A LA COMISIN PARA QUE
TODOS LOS EMPLEADOS QUE GANAN COMISIONES. ORDENAR LOS
DATOS EN ORDEN DESCENDENTE DE SUELDO Y COMISIONES.

DIEZ
10. MOSTRAR LOS APELLIDOS DE LOS EMPLEADOS DONDE LA TERCERA
LETRA DEL NOMBRE ES UN
ONCE
11. MOSTRAR EL LTIMO NOMBRE DE TODOS LOS EMPLEADOS QUE
TIENEN UNA A Y UNA E EN SU APELLIDO.

DOCE
12. MOSTRAR EL LTIMO NOMBRE, TRABAJO Y SALARIO DE TODOS LOS
EMPLEADOS CUYO TRABAJO ES REPRESENTANTE DE VENTAS O
EMPLEADO DE STOCK Y CUYO SALARIO NO ES IGUAL A $2.500, $3.500 O
7.000 DLARES.

TRECE
13. MODIFICAR LAB2_6.SQL PARA MOSTRAR EL APELLIDO, EL SUELDO, Y
A LA COMISIN PARA QUE TODOS LOS EMPLEADOS CUYO IMPORTE DE
LA COMISIN ES DEL 20%.
VOLVER A GUARDAR LAB2_6.SQL COMO LAB2_13.SQL. VUELVA A
EJECUTAR LA INSTRUCCIN EN LAB2_13.SQL.
Practica 3

Pregunta 1
Write a query to display the current date. Label the column Date.

Pregunta 2
For each employee, display the employee number, last_name, salary, and salary increased by
15% and expressed as a whole number. Label the column NewSalary. Place your SQL
statement in a text file named lab3_2.sql.
Pregunta 3
Run your query in the file lab3_2.sql.

Pregunta 4
Modify your query lab3_2.sqlto add a column that subtracts the old salary from
the new salary. Label the column Increase. Save the contents of the file as lab3_4.sql.
Run the revised query.
Pregunta 5
Write a query that displays the employees last names with the first letter capitalized and all
other letters lowercase, and the length of the names, for all employees whose name starts with
J, A, or M. Give each column an appropriate label. Sort the results by the employees last
names.

Pregunta 6

For each employee, display the employees last name, and calculate the number of months
between today and the date the employee was hired. Label the column MONTHS_WORKED.
Order your results by the number of months employed. Round the number of months up to the
closest whole number.
Pregunta 7
Write a query that produces the following for each employee: <employeelast
name>earns<salary>monthlybutwants<3times salary>. Label the
column DreamSalaries.
Pregunta 8
Create a query to display the last name and salary for all employees. Format the salary to be 15
characters long, left-padded with $. Label the column SALARY.
Pregunta 9
Display each employees last name, hire date, and salary review date, which is
the first Monday after six months of service. Label the column REVIEW. Format
the dates to appear in the format similar to Monday, the Thirty-First of July,
2000.

Pregunta 10
Display the last name, hire date, and day of the week on which the employee
started. Label the column DAY. Order the results by the day of the week starting
with Monday.

Pregunta 11
Create a query that displays the employees last names and commission
amounts. If an employee does not earn commission, put No Commission.
Label the column COMM.
Pregunta 12
Create a query that displays the employees last names and indicates the
amounts of their annual salaries with asterisks. Each asterisk signifies a
thousand dollars. Sort the data indescending order of salary. Label the column
EMPLOYEES_AND_THEIR_SALARIES.

Pregunta 13
Using the DECODEfunction, write a query that displays the grade of all employees based on the
value of the column JOB_ID, as per the following data:

Pregunta 14
Rewrite the statement in the preceding question using the CASEsyntax.
PRACTICA 4
PREGUNTA 1
Write a query to display the last name, department number, and department
name for all employees.

PREGUNTA 2
Create a unique listing of all jobs that are in department 80. Include the location of the
department in the output.
PREGUNTA 3
Write a query to display the employee last name, department name, location
ID, and city of all employees who earn a commission.

PREGUNTA 4
Display the employee last name and department name for all employees who
have an a(lowercase) in their last names. Place your SQL statement in a text
file named lab4_4.sql.
PREGUNTA 5
Write a query to display the last name, job, department number, and
department name for all employees who work in Toronto.

PREGUNTA 6
Display the employee last name and employee number along with their
managers last name and manager number. Label the columns Employee, Emp#,
Manager, and Mgr#, respectively.

PREGUNTA 7
Modify lab4_6.sql to display all employees including King, who has no manager.
Order the results by the employee number.
PREGUNTA 8
Create a query that displays employee last names, department numbers, and all theemployees who
work in the same department as a given employee. Give each column an appropriate label.

PREGUNTA 9
PREGUNTA 10
Create a query to display the name and hire date of any employee hired after
employee Davies.
PREGUNTA 11
Display the names and hire dates for all employees who were hired before their managers,
along with their managers names and hire dates. Label the columns Employee, Emp
Hired, Manager, and MgrHired, respectively.
PRACTICA # 5

PREGUNTA 1
Group functions work across many rows to produce one result per group.
R= VERDADERO

PREGUNTA 2
Group functions include nulls in calculations.
R= Falso. Las funciones de grupo ignoran valores nulos. Si deseamos incluir
valores nulos, podemos utilizar la funcin NVL.

PREGUNTA 3
The WHERE clause restricts rows prior to inclusion in a group calculation.
R= VERDADERO

PREGUNTA 4
Display the highest, lowest, sum, and average salary of all employees. Label the columns
Maximum, Minimum, Sum, and Average, respectively. Round your results to the nearest whole
number.
PREGUNTA 5
Modify the query in lab5_4.sqlto display the minimum, maximum, sum, and average salary
for each job type.

PREGUNTA 6
Write a query to display the number of people with the same job.
PREGUNTA 7
Determine the number of managers without listing them. Label the column Numberof
Managers. Hint: Use the MANAGER_IDcolumn to determine the number of managers.

PREGUNTA 8
Write a query that displays the difference between the highest and lowest salaries. Label the
column DIFFERENCE.
PREGUNTA 9
Display the manager number and the salary of the lowest paid employee for that manager.
Exclude anyone whose manager is not known. Exclude any groups where the minimum
salary is $6,000 or less. Sort the output in descending order of salary.

PREGUNTA 10
Write a query to display each departments name, location, number of employees, and the
average salary for all employees in that department. Label the columns Name, Location,
NumberofPeople, and Salary, respectively. Round the average salary to two decimal
places.
PREGUNTA 11
Create a query that will display the total number of employees and, of that total, the number of
employees hired in 1995, 1996, 1997, and 1998. Create appropriate column headings.

PREGUNTA 12
Create a matrix query to display the job, the salary for that job based on department number,
and the total salary for that job, for departments 20, 50, 80, and 90, giving each column an
appropriate heading.
PRACTICA 6
PREGUNTA 1
Write a query to display the last name and hire date of any employee in the same
department as Zlotkey. Exclude Zlotkey.

PREGUNTA 2
Create a query to display the employee numbers and last names of all employees who earn more
than the average salary. Sort the results in ascending order of salary.
PREGUNTA 3
Write a query that displays the employee numbers and last names of all employees who work in
a department with any employee whose last name contains a u. Place your SQL statement in a
text file named lab6_3.sql.

PREGUNTA 4
Display the last name, department number, and job ID of all employees whose
department location ID is 1700.
PREGUNTA 5
Display the last name and salary of every employee who reports to King.

PREGUNTA 6
Display the department number, last name, and job ID for every employee in the Executive
department.

PREGUNTA 7
Modify the query in lab6_3.sqlto display the employee numbers, last names, and salaries
of all employees who earn more than the average salary and who work in a department with
any employee with a u in their name. Resave lab6_3.sqlto lab6_7.sql. Run the
statement in lab6_7.sql.
PRACTICA 7
Pregunta 1
True or false
Determine whether the following two statements are true or false:
1. The following statement is valid:

DEFINE&p_val=100

Falso, lo correcto seraDEFINEp_val=100

Pregunta 2
Falso, Define es un comando de iSQL*Pluss

Pregunta 3
Pregunta 4

Vous aimerez peut-être aussi