Table values being truncated

Asked

Viewed 194 times

1

I made code in the declaration part of the real number that word balance that it will receive a number with 6 digits and 2 two decimal places after the comma, except that all values that I enter are truncated, how to solve ?

create database uri
default character set utf8
default collate utf8_general_ci;

use uri;

create table pessoas(

 id int not null auto_increment,
 nome varchar(30),
 rua varchar(30),
 cidade varchar(30),
 regiao char(3),
 saldo decimal(6,2),
 primary key(id)

) default charset utf8;

insert into pessoas values
('1','Pedro Augusto da Rocha','Rua Pedro Carlos Hoffman','Porto Alegre','RS','700,00'),
('2','Antonio Carlos Mamel','Av. Pinheiros','Belo Horizonte','MG','3500,50'),
('3','Luiza Augusta Mhor','Rua Salto Grande','Niteroi','RJ','4000,00'),
('4','Jane Ester','Av 7 de setembro','Erechim','RS','800,00'),
('5','Marcos Antônio dos Santos','Av Farrapos','Porto Alegre','RS','4250,25');
SELECT nome FROM pessoas WHERE regiao = 'RS';
  • Truncated as?

  • 1

    Swap commas for dots before inserting in the seat.

  • Thanks @bfavaretto

2 answers

2

2

Change "," to "." because the field is of the decimal type (only accepts number and the separator to decimal places is the point)

Example:

insert into pessoas values
('1','Pedro Augusto da Rocha','Rua Pedro Carlos Hoffman','Porto Alegre','RS','700.00')

Browser other questions tagged

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