Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entrega Semana 4 - DOUGLAS MARÇAL ROGÉRIO #231

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added modelos/Conceitual_douglas marcal.brM3
Binary file not shown.
Binary file added modelos/Lógico_douglas marcal.brM3
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modelos/print_modelo lógico_douglas marcal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions sql/comandos/comandos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
--cadastro de endereço do colaborador
INSERT INTO brh.endereco (cep, uf, cidade, bairro)
VALUES ('01928-374', 'MG', 'Belo Horizonte', 'Parque da Saudade');

-- cadastro do novo colaborador
INSERT INTO brh.colaborador (matricula, nome, cpf, salario, departamento, cep, logradouro, complemento_endereco)
VALUES ('Z124', 'Fulano de Tal', '098.987.876-76', '12500', 'DEPTI', '01928-374', 'Rua Legal', 'Condomínio Tranquilo');

-- cadastro dos telefones
INSERT INTO brh.telefone_colaborador (colaborador, numero, tipo)
VALUES ('Z124', '(61) 99999-9999', 'M');

INSERT INTO brh.telefone_colaborador (colaborador, numero, tipo)
VALUES ('Z124', '(61) 3030-4040', 'R');

-- cadastro dos e-mails
INSERT INTO brh.email_colaborador (colaborador, email, tipo)
VALUES ('Z124', 'fulanodetal@email.com', 'P');

INSERT INTO brh.email_colaborador (colaborador, email, tipo)
VALUES ('Z124', 'fulanodetal@corporativo.com', 'T');

-- cadastro de dependentes

INSERT INTO brh.dependente (cpf, colaborador, nome, parentesco, data_nascimento)
VALUES ('111.333.555-77', 'Z124', 'Cicrana de Tal', 'Cônjuge', to_date('1990-03-27', 'yyyy-mm-dd'));

INSERT INTO brh.dependente (cpf, colaborador, nome, parentesco, data_nascimento)
VALUES ('222.444.666-88', 'Z124', 'Beltrana de Tal', 'Filho(a)', to_date('2021-03-11', 'yyyy-mm-dd'));

-- cadstro de projeto

INSERT INTO brh.projeto (id, nome, responsavel, inicio, fim)
VALUES (5, 'BI', 'A123', to_date('2024-06-17', 'yyyy-mm-dd'), null);

-- cadastro de papel

INSERT INTO brh.papel (id, nome)
VALUES (8, 'Especialista de Negócios');

-- atribuição ao projeto

INSERT INTO brh.atribuicao (projeto, colaborador, papel)
VALUES (5, 'Z124', 8);

-- consulta sigla e nome departamento

select nome, sigla from brh.departamento order by nome;

-- consulta nomes dos dependentes

select brh.colaborador.nome as colaborador, brh.dependente.nome as dependente, brh.dependente.data_nascimento, brh.dependente.parentesco
from brh.colaborador
inner join brh.dependente
on brh.dependente.colaborador = brh.colaborador.matricula
order by brh.colaborador.nome, brh.dependente.nome;

-- EXCLUSÃO DEPARTAMENTO SECAP

--consulta
select * from brh.colaborador where departamento = 'SECAP'
-- matrículas impactadas = H123, M123, R123, W123

--exclusão dependentes
delete from brh.dependente where colaborador = 'H123'
delete from brh.dependente where colaborador = 'M123'
delete from brh.dependente where colaborador = 'R123'
delete from brh.dependente where colaborador = 'W123'

--exclusão e-mail

delete from brh.email_colaborador where colaborador = 'H123'
delete from brh.email_colaborador where colaborador = 'M123'
delete from brh.email_colaborador where colaborador = 'R123'
delete from brh.email_colaborador where colaborador = 'W123'

-- exclusão telefone

delete from brh.telefone_colaborador where colaborador = 'H123'
delete from brh.telefone_colaborador where colaborador = 'M123'
delete from brh.telefone_colaborador where colaborador = 'R123'
delete from brh.telefone_colaborador where colaborador = 'W123'

-- exclusão colaborador

delete from brh.colaborador where matricula = 'H123'
delete from brh.colaborador where matricula = 'M123'
delete from brh.colaborador where matricula = 'R123'
delete from brh.colaborador where matricula = 'W123'

-- exclusão departamento

delete from brh.departamento where sigla = 'SECAP'

-- RELATÓRIO DE CONTATO DOS COLABORADORES (APÓS EXTINÇÃO DO SECAP)

select brh.colaborador.nome, brh.email_colaborador.email, brh.telefone_colaborador.numero
from brh.colaborador
inner join brh.email_colaborador
on brh.colaborador.matricula = brh.email_colaborador.colaborador
inner join brh.telefone_colaborador
on brh.colaborador.matricula = brh.telefone_colaborador.colaborador
where brh.email_colaborador.tipo = 'T' and brh.telefone_colaborador.tipo = 'M'
order by nome








84 changes: 84 additions & 0 deletions sql/plsql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- CRIA��O DE PROCEDURE PARA INCLUS�O DE PROJETO

CREATE OR REPLACE PROCEDURE brh.insere_projeto (
p_NOME IN BRH.PROJETO.NOME%type,
p_RESPONSAVEL IN BRH.PROJETO.RESPONSAVEL%type
)
IS
BEGIN
INSERT INTO BRH.PROJETO (NOME, RESPONSAVEL, INICIO)
VALUES (p_NOME, p_RESPONSAVEL, SYSDATE);
END;

EXECUTE brh.insere_projeto('Teste Inser��o', 'X123');

SELECT * FROM BRH.PROJETO;

-- CRIA��O DE FUN��O PARA C�LCULO DE IDADE

CREATE OR REPLACE FUNCTION brh.calcula_idade (
p_DATA_NASCIMENTO IN DATE
)
RETURN NUMBER
IS
v_IDADE NUMBER;
BEGIN
v_IDADE := FLOOR(MONTHS_BETWEEN(SYSDATE, p_DATA_NASCIMENTO)/12);
RETURN v_IDADE;
END;

-- TESTE DE FUN��O

SELECT brh.calcula_idade (TO_DATE('1984-06-13', 'YYYY-MM-DD')) FROM DUAL;

SELECT DATA_NASCIMENTO, brh.calcula_idade(DATA_NASCIMENTO) AS IDADE FROM BRH.DEPENDENTE;

-- CRIA��O DE FUN��O PARA FINALIZA��O DE PROJETO

CREATE OR REPLACE FUNCTION brh.finaliza_projeto (
p_ID IN BRH.PROJETO.ID%type
)
RETURN DATE
IS
v_FIM DATE;
BEGIN
v_FIM := SYSDATE;
UPDATE BRH.PROJETO
SET FIM = v_FIM WHERE ID = p_ID;

RETURN v_FIM;
END;

-- TESTE DA FUN��O

SET SERVEROUTPUT ON;

DECLARE
v_ID NUMBER := 1;
v_FIM DATE;
BEGIN
v_FIM := brh.finaliza_projeto(v_ID);
dbms_output.put_line('Fim do projeto em ' || v_FIM);
END;

SELECT * FROM BRH.PROJETO;

-- VALIDA��O DE NOVOS PROJETOS

CREATE OR REPLACE PROCEDURE brh.insere_projeto (
p_NOME IN BRH.PROJETO.NOME%type,
p_RESPONSAVEL IN BRH.PROJETO.RESPONSAVEL%type
)
IS
BEGIN
IF LENGTH(p_NOME) < 2 OR p_NOME IS NULL THEN
RAISE_APPLICATION_ERROR(-20001, 'Nome de projeto inv�lido! Deve ter dois ou mais caracteres.');
ELSE
INSERT INTO BRH.PROJETO (NOME, RESPONSAVEL, INICIO)
VALUES (p_NOME, p_RESPONSAVEL, SYSDATE);
END IF;
END;

-- TESTE PROCEDURE

EXECUTE brh.insere_projeto('K', 'X123');
70 changes: 70 additions & 0 deletions sql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
create user brh
identified by brh
default tablespace users
quota unlimited on users

create table tb_departamento (
sigla varchar2(5) not null,
nome varchar2(50) not null,
chefe varchar2(50) not null,
departamento_superior varchar2(5)
)

create table tb_colaborador (
matricula varchar2(8) not null,
cpf char(14) not null,
nome varchar2(50) not null,
salario decimal(10,2) not null,
logradouro varchar2(150) not null,
complemento varchar2(30) not null,
cep varchar2(10) not null,
departamento varchar2(5) not null
)

create table tb_cep (
cep varchar2(10) not null,
bairro varchar2(50) not null,
cidade varchar2(50) not null,
estado varchar2(2) not null
)

create table tb_telefone_colaborador (
matricula varchar2(8) not null,
numero varchar2(14) not null,
tipo char(3) not null
)

create table tb_email_colaborador (
matricula varchar2(8) not null,
email varchar2(50) not null,
tipo char(3) not null
)

create table tb_dependentes (
cpf char(14) not null,
matricula_colaborador varchar2(8) not null,
nome varchar2(50) not null,
data_nascimento date not null,
parentesco varchar2(20) not null
)

create table tb_projetos (
id integer generated by default as identity (start with 1) not null,
nome varchar2(100) not null,
responsavel varchar2(8) not null,
inicio date not null,
fim date
)

create table tb_atribuicao (
colaborador varchar2(8) not null,
projeto integer not null,
papel integer not null
)

create table tb_papel (
id integer generated by default as identity (start with 1) not null,
nome varchar2(100) not null
);