我试图在PostgreSQL数据库中运行以下DML语句:
INSERT INTO HMS_RESERVE_CANCEL_DTL
(DIVISION_CODE,
UNIT_CODE,
RESERVATION_NO,
RESERVATION_DATE,
CANCELLATION_NO,
CANCELLATION_DATE,
CANCELLED_AT_UNIT,
CANCELLATION_AMOUNT,
CANCELLED_BY,
CANCELLATION_REASON,
REFUND_AMOUNT,
POSTED_TO_FAS,
CANCEL_PER,
room_type,
no_of_rooms,
taxes )
values(
'103',
'10303',
'GHA1314HTLRS000157',
case trim('') when trim('08-05-2013') then null else to_date('08-05-2013','DD-MM-YYYY HH24:MI:SS') end,
'GHA1314HTLCL000002',
current_date,
'10303',
5200.0,
'001721',
'my parsanal',
'53260.00',
'N',
10.0,
'02',
'10',
'10320.0')
以上语句开始但很快失败,并显示以下错误消息:
ERROR: numeric field overflow
SQL state: 22003
Detail: The absolute value is greater than or equal to 10^4 for field with precision 6, scale 2.
请帮我摆脱这个错误(或者至少指出我正确的方向)。我的表(hms_rserve_cancel_dtl
)的表结构如下:
CREATE TABLE hms_reserve_cancel_dtl
(
division_code character varying(3) NOT NULL,
unit_code character varying(5) NOT NULL,
reservation_no character varying(20) NOT NULL,
reservation_date date NOT NULL,
cancellation_no character varying(20) NOT NULL,
cancellation_date date NOT NULL,
cancelled_at_unit character varying(15) NOT NULL,
cancellation_amount numeric(7,2),
cancelled_by character varying(35),
cancellation_reason character varying(200),
refund_amount numeric(7,2),
posted_to_fas character(1) DEFAULT 'N'::bpchar,
posted_date date,
remarks character varying(200),
status character(1) DEFAULT 'A'::bpchar,
cancel_per numeric(7,2),
room_type character varying(2),
no_of_rooms character varying(2),
refund_status character(1),
refunded_date date,
taxes numeric(6,2) DEFAULT 0.00,
CONSTRAINT hms_reserve_cancel_dtl_div_unit_code_fkey FOREIGN KEY (division_code, unit_code)
REFERENCES aptdc_units_mst (division_code, unit_code) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT hms_reserve_cancel_dtl_reservation_no_fkey FOREIGN KEY (reservation_no, room_type)
REFERENCES hms_reservation_mst (reservation_no, room_type) MATCH SIMPLE
ON UPDATE RESTRICT ON DELETE RESTRICT
)
WITHOUT OIDS;
ALTER TABLE hms_reserve_cancel_dtl OWNER TO postgres;
GRANT ALL ON TABLE hms_reserve_cancel_dtl TO postgres;
答案 0 :(得分:1)
数字的刻度是小数点右侧小数部分的小数位数。数字的精度是整数中有效数字的总数,即小数点两边的位数。所以数字23.5141的精度为6,比例为4.
例如10123.435
不适合numeric(4,2)
create table tmp (
a numeric (8,5)
);
/* ok */ insert into tmp values (123.12345);
/* ok */ insert into tmp values (1.1);
-- this will result in 1.12346, because precicion is set to 5!
insert into tmp values (1.123456);
/* owerflow */ insert into tmp values (1000);
-- because of number gets rounded to 5 decimal numbers:
/* owerflow */ insert into tmp values (999.99999999999999999999);
答案 1 :(得分:1)
您的纳税字段设计为数字(6,2),表示总共6位数字。小数点前4和后面2。您提供的值在小数点前有5位数,因此它不适合。
答案 2 :(得分:1)
您已将税金定义为最多6位数,其中2位于小数部分,这意味着9999.99是您可以插入的最大值。在您的插入中,您尝试插入10320.0,这对于此列来说太大了。