-1
I created this bank:
create table aluno(
codaluno int primary key,
nome varchar(30),
datanasc date);
create table curso(
codcurso int primary key,
descricao_c varchar(200));
create table disciplina(
coddisc int primary key,
descricao_d varchar(200),
creditos int,
cod_curso int,
constraint fk_codcurso foreign key (cod_curso) references curso (codcurso));
create table matricula(
cod_aluno int,
cod_disc int,
data date,
nota1 number(3,1),
nota2 number(3,1),
nota3 number(3,1),
constraint fk_codaluno foreign key (cod_aluno) references aluno (codaluno),
constraint fk_coddisc foreign key (cod_disc) references disciplina (coddisc));
create table historico(
semestre int,
nota_final number(3,1),
cod_alun int,
cod_dis int,
constraint fk_codal foreign key (cod_alun) references aluno (codaluno),
constraint fk_coddi foreign key (cod_dis) references disciplina (coddisc));
insert into aluno values (01, 'John', to_date('07/04/1998', 'DD/MM/YYYY'));
insert into aluno values (02, 'Anna', to_date('03/07/2000', 'DD/MM/YYYY'));
insert into aluno values (03, 'Marcio', to_date('05/12/1995', 'DD/MM/YYYY'));
insert into curso values (01, 'Computação');
insert into curso values (02, 'Direito');
insert into disciplina values (01, 'Algoritmos 1', 4, 1);
insert into disciplina values (02, 'Código Penal', 4, 2);
insert into matricula values (01, 01, to_date('08/01/2018', 'DD/MM/YYYY'), 9.3, 10.0, 8.8);
insert into matricula values (02, 01, to_date('07/01/2019', 'DD/MM/YYYY'), 8.7, 7.5, 10.0);
insert into matricula values (03, 01, to_date('09/01/2017', 'DD/MM/YYYY'), 10.0, 10.0, 9.5);
insert into historico values (01, 0.0, 01, 01);
insert into historico values (01, 0.0, 02, 01);
insert into historico values (01, 0.0, 03, 01);
I would like to know how to take the average of a student’s 3 grades and insert this value into the final grade that is in the historical table. Obviously I will have to update it and I tried to do this through a trial:
create or replace procedure UPDATEhistorico (
p_nota_final in historico.nota_final%TYPE)
is
begin
update historico set AVG(nota_final)=p_notafinal where aluno.codaluno = matricula.cod_aluno
and disciplina.coddisc = matricula.cod_disc
and curso.codcurso = disciplina.cod_curso;
end;
It makes no sense what I tried to do, so I came to ask for help.
Answer was negative, so I decided to improve it. I improved the command
update
includingand historico.semestre = 1
in charge, I used theNVL
and explained the reason, I included a professional vision to warn about points of attention and suggest the use ofTrigger
if necessary. Should anyone be able to say what else the reply can be improved on, I would appreciate the time taken to make such a comment and I will seek to apply it in this reply and in the future.– Clarck Maciel
Second or third answer of yours that I see being denied for no reason that I understand. Making it clear that it is my personal opinion, but and I recently went through a similar situation I was being systematically negativated by no personal motivation and no technical criteria. If you think it’s a case of systematic voting, flag the publications you suspect asking for an audit. In my case it solved and I was able to reverse the vote.
– Augusto Vasques