Você está na página 1de 3

BD- lab

SIMULADO de SQL – 3, Funções de Linha

Primeiramente conecte-se à base de dados Oracle SQL Live.


Execute o comando Oracle: Desc HR.employees
para conhecer o schema da tabela.

Execute os seguintes comandos SQL e analise a resposta do SGBD:


1) Mostre a estrutura (esquema) da tabela DEPARTMENTS . Em seguida, apresente todos os dados desta tabela.
DESCRIBE HR.departments
SELECT * FROM HR.departments;

2) Faça uma query para apresentar os códigos utilizados no campo jobs da tabela display EMPLOYEES, mas sem
repetições.
SELECT DISTINCT job_id
FROM HR.employees;
3) select FIRST_NAME, LAST_NAME , DEPARTMENT_ID, trunc(salary/ nvl(COMMISSION_PCT,1))
from HR.employees
where DEPARTMENT_ID=80;
4) select FIRST_NAME, LAST_NAME, JOB_ID
from HR.employees
where lower(JOB_ID)='pu_clerk'
5) Identifique 4 erros na sintaxe do commando a seguir:
SELECT employee_id, last_name
sal x 12 ANNUAL SALARY FROM employees;

6) select FIRST_NAME as nome, LAST_NAME as sobrenome, salary as Salario


from HR.employees
where salary < 15000
7) select FIRST_NAME as nome, LAST_NAME as sobrenome
from HR.employees
where salary < 10000 AND PHONE_NUMBER is not NULL;
8) select lower(FIRST_NAME) as nome, concat(lower(EMAIL),' ' ), lower(LAST_NAME) as Sobrenome
from HR.employees
where salary < 20000;
9) select lower(FIRST_NAME) as nome, concat(lower(EMAIL), '#'), lower(LAST_NAME) as Email
from HR.employees
where salary < 20000 AND COMMISSION_PCT is NULL;
10) select EMPLOYEE_ID as chapa, sysdate-HIRE_DATE, MANAGER_ID as Gerente
from HR.employees
where MANAGER_ID= 114

Prof. Luiz Carlos Magrini 1


BD- lab
11) Apresente o sobrenome e salário dos empregados que ganhem mais de $12,000.
SELECT last_name, salary
FROM HR.employees
WHERE salary > 12000;
12) Modifi que o comando anterior para restringindo a consulta apenas para aqueles funcionários cujo salário não esteja
entre $5,000 e $12,000.
SELECT last_name, salary
FROM HR.employees
WHERE salary NOT BETWEEN 5000 AND 12000;
13) Crie uma consulta para mostrar o sobrenome e o número do departamento do empregado de código de registro
176.
SELECT last_name, department_id
FROM HR.employees
WHERE employee_id = 176;
14) Mostre os empregados contratados entre 20 de Fevereiro de 1998 e 01 de Maio de 1998. Para cada um dos
funcionários apresente o sobrenome, o job ID, e a data de contratação. Ordene os registros obtidos em ordem
ascendente da data de contratação
SELECT last_name, job_id, hire_date
FROM HR.employees
WHERE hire_date BETWEEN '20-Feb-1998' AND '01-May-1998'
ORDER BY hire_date;
15) select EMPLOYEE_ID as chapa, to_char(sysdate,'dd-MM-yyyy') as dia, to_char(sysdate, 'hh24:mi') as hora,
to_char(HIRE_DATE,'dd-mm-yyyy') as "Data Contratação", MANAGER_ID
from HR.employees
where MANAGER_ID= 114;
16) select EMPLOYEE_ID as chapa, to_char(sysdate,’dd-MON-yyyy’) as dia, to_char(sysdate, ‘hh24:mi’) as hora,
to_char(HIRE_DATE,'dd-mm-yyyy' ) as "data contratação", MANAGER_ID
from HR.employees where MANAGER_ID= 114
17) select EMPLOYEE_ID as chapa, to_char(sysdate,’dd-MONTH-yyyy’) as dia, to_char(sysdate, ‘hh24:mi’) as hora,
to_char(HIRE_DATE,'dd-mm-yyyy' ) as "data contratação", MANAGER_ID
from HR.employees where MANAGER_ID= 114
18) select EMPLOYEE_ID as chapa, to_char(sysdate, ’Alphaville Dy dd de MONTH de yyyy’) as dia, to_char(sysdate,
‘hh24:mi’) as hora, to_char(HIRE_DATE,'dd-mm-yyyy' ) as "data contratação", JOB_ID
from HR.employees
where JOB_ID = ‘IT_PROG’
19) select EMPLOYEE_ID as chapa, SYSDATE as "dia hora", job_ID
from HR.employees
where job_ID='PU_CLERK'
20) select FIRST_NAME, (sysdate -HIRE_DATE)/365 as "anos de casa"
from HR.employees
21) select FIRST_NAME, LAST_NAME, HIRE_DATE
from HR.employees
where (sysdate -HIRE_DATE)/365 < 20
22) select FIRST_NAME, LAST_NAME,DEPARTMENT_ID, (sysdate-HIRE_DATE)/(365*24)
from HR.employees
where DEPARTMENT_ID = 'D11' OR job_ID='PU_CLERK'
Prof. Luiz Carlos Magrini 2
BD- lab
order by DEPARTMENT_ID, FIRST_NAME
23) select EMPLOYEE_ID, concat(FIRST_NAME," ", LAST_NAME)
from HR.employees
where length(FIRST_NAME) < 5
24) select EMPLOYEE_ID, concat(FIRST_NAME," ", LAST_NAME, “Telefone: “ , PHONE_NUMBER, " ",)
from HR.employees
25) select EMPLOYEE_ID, LAST_NAME, DEPARTMENT_ID, salary
from HR.employees
where salary > 35000.
order by salary desc
26) select FIRST_NAME, JOB_ID_ID
from HR.employees
where substr(JOB_ID_ID, 6,8) = 'REP'
order by JOB_ID_ID
27) select EMPLOYEE_ID, LAST_NAME, first_name, instr(first_NAME,'el'), length(first_NAME)
from HR.employees
where substr(LAST_NAME, instr(LAST_NAME,'el'), length(LAST_NAME)) = 'el';
28) select FIRST_NAME, salary/ nvl(COMMISSION_PCT,1)
from HR.employees
where DEPARTMENT_ID='100'
29) select FIRST_NAME, round(salary/ nvl(COMMISSION_PCT,1) ,3)
from HR.employees
where DEPARTMENT_ID='100'
30) select FIRST_NAME, round(salary/ nvl(COMMISSION_PCT,1), 2 )
from HR.employees
where DEPARTMENT_ID='100'
31) select FIRST_NAME, truncate(salary/ nvl(COMMISSION_PCT,1), 1)
from HR.employees
where DEPARTMENT_ID='100'
32) select FIRST_NAME, truncate(salary/ nvl(COMMISSION_PCT,1), 0)
from HR.employees
where DEPARTMENT_ID='100'
33) Liste o sobrenome e salario dos empregados que ganhem entre $5,000 e $12,000, e que estão alocados ao
departamento 20 ou 50. Atribua um nome em portugues às colunas Employee e Monthly Salary, respectivamente.
SELECT last_name "Empregado", salary "Salrio Mensal"
FROM HR.employees
WHERE salary BETWEEN 5000 AND 12000
AND department_id IN (20, 50);
34) Mostre o sobrenome de todos empregados que tenham a letra "a" e a letra "e" no seu sobrenome.
SELECT last_name
FROM HR.employees
WHERE last_name LIKE '%a%'
AND last_name LIKE '%e%';

Prof. Luiz Carlos Magrini 3

Você também pode gostar