Functions in Mysql phpMyAdmin

Asked

Viewed 14 times

-3

I’m trying to do the following exercise

1 - Develop a Function that returns the name of the liquidator by passing as parameter the identifier of the liquidator. Then use the created Function to develop an instruction that presents the data of the condominiums (name, address) and the name of the liquidator of each one of them.

2 - Develop a Function that calculates the value of the condominium rate from the value of the apartment, passing as parameter the identifier of the apartment and the percentage applied to the value to calculate the rate. Then use the created Function to develop an instruction that presents the data of the apartments (number, value) of a given condominium and the fee to be paid.

create database imobiliaria;

use imobiliaria;

create table sindico (
  matricula int(3) not null auto_increment,
  nome varchar(80) default null,
  endereco varchar(80) default null,
  telefone varchar(15) default null,
  primary key (matricula)
);

insert into sindico values (1,'antonio carlos','avenida santos dummont, número 789, califórnia, são paulo','(11) 3456-6787'),(2,'sidnei delgado','alameda xv de novembro, número 123, jockey club, são paulo','(11) 3452-4562');

create table condominio (
  codigo int(5) not null auto_increment,
  nome varchar(50) default null,
  endereco varchar(80) default null,
  matricula_sind int(3) default null,
  primary key (codigo),
  key fx_cond_sindico (matricula_sind),
  constraint fx_cond_sindico foreign key (matricula_sind) references sindico (matricula)
);

insert into condominio values (1,'condomínio são paulo','alameda getulio vargas, número 897, centro, são paulo',1),(2,'condomínio brasil','avenida general gusmão, número 453, penha, são paulo',2);

create table apartamento (
  numero varchar(5) not null,
  tipo varchar(20) default null,
  codigo_cond int(5) default null,
  valor double(10,2) default '0.00',
  primary key (numero),
  key fk_ap_cond (codigo_cond),
  constraint fk_ap_cond foreign key (codigo_cond) references condominio (codigo)
);

insert into apartamento values ('a101','padrão',1,100000.00),('a201','padrão',1,115000.00),('a301','padrão',1,125000.00),('a401','padrão',1,135000.00),('a501','cobertura',1,150000.00),('b101','padrão',2,200000.00),('b201','padrão',2,215000.00),('b301','padrão',2,225000.00),('b401','padrão',2,235000.00),('b501','cobertura',2,250000.00);

create table garagem (
  numero int(3) not null auto_increment,
  tipo varchar(20) default null,
  numero_ap varchar(5) default null,
  primary key (numero),
  key fk_gar_apartamento (numero_ap),
  constraint fk_gar_apartamento foreign key (numero_ap) references apartamento (numero)
);

insert into garagem values (1,'padrão','a101'),(2,'padrão','a201'),(3,'padrão','a301'),(4,'padrão','a401'),(5,'coberta','a501'),(6,'padrão','b101'),(7,'padrão','b101'),(8,'padrão','b201'),(9,'padrão','b201'),(10,'padrão','b301'),(11,'padrão','b301'),(12,'padrão','b401'),(13,'padrão','b401'),(14,'coberta','b501'),(15,'coberta','b501');

create table proprietario (
  rg varchar(15) not null,
  nome varchar(80) default null,
  telefone varchar(15) default null,
  email varchar(50) default null,
  primary key (rg)
);

insert into proprietario values ('12345678-0','carlos eduardo','(11) 3256-7890','[email protected]'),('32145678-4','oswaldo lima','(11) 2314-9876','[email protected]'),('32156788-0','pedro castro','(11) 3452-8743','[email protected]'),('46536267-3','maria luiza','(11) 2345-1627','[email protected]'),('54367281-2','joana darc','(11) 4563-2315','[email protected]'),('74853928-2','benedito goes','(11) 3427-4132','[email protected]'),('76534126-4','matheus henrique','(11) 2234-1123','[email protected]'),('98635314-5','augusto silva','(11) 4122-2134','[email protected]'),('99987271-1','marcos vinicius','(11) 2124-2427','[email protected]');

create table proprietario_apartamento (
  prop_ap_id int(3) not null auto_increment,
  numero_ap varchar(5) default null,
  rg_prop varchar(15) default null,
  primary key (prop_ap_id),
  key fk_pa_apartamento (numero_ap),
  key fk_pa_proprietario (rg_prop),
  constraint fk_pa_apartamento foreign key (numero_ap) references apartamento (numero),
  constraint fk_pa_proprietario foreign key (rg_prop) references proprietario (rg)
);

insert into proprietario_apartamento values (1,'a101','12345678-0'),(2,'a201','32145678-4'),(3,'a301','32156788-0'),(4,'a401','46536267-3'),(5,'a501','54367281-2'),(6,'b101','74853928-2'),(7,'b201','76534126-4'),(8,'b301','98635314-5'),(9,'b401','99987271-1'),(10,'b501','99987271-1');

I tried the following solutions but returns error

CREATE FUNCTION return_sindico (matricula int)
RETURNS varchar(50)
BEGIN
 
 declare nome varchar(50);
 set nome = (select s.nome from sindico s where s.matricula = matricula); 
 
END $$
DELIMITER ;

DELIMITER $$
CREATE FUNCTION taxa_condominio (numero_apartamento varchar(50), porcentual double)
RETURNS double(10, 2)
BEGIN
 
declare taxa double (10,2);
set taxa = (select a.valor from apartamento a where a.numero = numero_apartamento);
set taxa = (percentual / 100) * taxa; 
 
END $$
DELIMITER ;

1320 - No RETURN found in FUNCTION real estate.

It seems to be all right I can’t identify the mistake

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.