一、其实当我们在选择使用int的类型的时候,不论是int(3)还是int(11),它在数据库里面存储的都是4个字节的长度,在使用int(3)的时候如果你输入的是10,会默认给你存储位010,也就是说这个3代表的是默认的一个长度,当你不足3位时,会帮你补全,当你超过3位时,就没有任何的影响。 除了在存储的时候稍微有点区别外,在我们使用的时候是没有任何区别的。int(10)也可以代表
2147483647这个 值int(11)也可以代表。要查看出不同效果记得在创建类型的时候加 zerofill这个值
表示用0填充,否则看不出效果的。我 们通常在创建数据库的时候都不会加入这个选项,所以可以
说他们之间是没有区别的。
DELIMITER $$
USE `mypos2`$$
DROP PROCEDURE IF EXISTS `thjlcp_new`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `thjlcp_new`(syid INT)
BEGIN
IF syid>0 THEN
DELETE FROM syjlb WHERE syjlb.syid=syid;
ELSE
/*增加一条负销售*/
INSERT syjlb(syyid,gkid,sysj,zffs,ysje,ssje,yhje,xszt,zzid)
SELECT syyid,gkid,NOW(),zffs,-ysje,-ssje,-yhje,-1,zzid
FROM syjlb WHERE syjlb.syid=-syid;
SET @syid_new=@@identity;
/*修改销售状态以免多次退货*/
UPDATE syjlb SET xszt=@syid_new WHERE syjlb.syid=-syid;
/*在销售表里面插入负销售*/
INSERT INTO symxb(syid,hpid,xssl,dj,lsj) SELECT @syid_new,hpid,-xssl,dj,lsj
FROM symxb WHERE symxb.syid=-syid;
/*变更库存*/
DROP TABLE IF EXISTS lsb;
CREATE TEMPORARY TABLE lsb(hpid INT,xssl NUMERIC(18,3));
INSERT INTO lsb(hpid,xssl) SELECT hpid,SUM(xssl) FROM symxb WHERE symxb.syid=-syid GROUP BY hpid;
UPDATE hpkcb b1,lsb b2 SET b1.kcsl=b1.kcsl+b2.xssl WHERE b1.hpid=b2.hpid;
/*如果是会员,还原积分*/
SELECT gkid INTO @hyid FROM syjlb WHERE syjlb.syid=-syid;
SELECT ssje INTO @ssje FROM syjlb WHERE syjlb.syid=-syid;
IF @hyid>10000 THEN
UPDATE hyxxb SET knye=knye+@ssje,kyjf=kyjf-FLOOR(@ssje) WHERE hyxxb.hyid=@hyid;
END IF;
END IF;
END$$
DELIMITER ;
退货业务实现
CREATE DEFINER=`root`@`localhost` PROCEDURE `xsjlcp_new`(syyid int,hyid int,ysje DECIMAL(18,2),ssje DECIMAL(18,2),zffs TINYINT,xsmx VARCHAR(1000))
BEGIN
-- 与销售有关业务的维护
-- 1.Syjlb(收银记录表) insert syyid(售货员id) gkid(顾客id) ysje(应收金额) ssje(实收金额) zffs(支付方式)需要从用户界面传过来syyid gkid ysje ssje zffs
INSERT INTO syjlb(syyid,gkid,ysje,ssje,zffs) values(syyid,hyid,ysje,ssje,zffs);
SET @syid=@@identity;
DROP TABLE IF EXISTS lsb;
CREATE TEMPORARY TABLE lsb(hpid INT,xssl DECIMAL(18,3));
WHILE (xsmx<>'') DO
SET @k=POSITION(','IN xsmx);
SET @hpid=LEFT(xsmx,@k-1);
SET xsmx=SUBSTR(xsmx,@k+1);
SET @k=POSITION(','IN xsmx);
SET @xssl=LEFT(xsmx,@k-1);
INSERT INTO lsb VALUES(@hpid,@xssl);
SET xsmx=SUBSTR(xsmx,@k+1);
END WHILE;
-- 2.Symxb(收银明细表) insert syid(售货id) hpid(货品id) xssl(销售数量) dj(定价) lsj(零售价) 需要从用户界面传过来:hpid xssl
insert into symxb(syid,hpid,xssl,dj,lsj)
SELECT @syid,lsb.hpid,xssl,lsj,cxj from lsb,hpmcb where lsb.hpid=hpmcb.Hpid;
-- 3.hpkcb(货品库存表) update 依据hpid(货品id),xssl(销售数量)更新kcsl 需要从用户界面传过来:hpid xssl
DROP TABLE IF EXISTS lsb1;
CREATE TEMPORARY TABLE lsb1(hpid INT,xssl DECIMAL(18,3));
INSERT INTO lsb1 SELECT hpid,SUM(xssl) FROM lsb GROUP BY hpid;
UPDATE hpkcb b1,lsb1 b2 SET b1.kcsl=b1.kcsl-b2.xssl WHERE b1.hpid=b2.hpid;
-- 4.hyxxb(会员信息表) update 依据hyid(货品id),ssje(实收金额)更新knye(卡内余额),kyjf (可用积分)需要从用户界面传过来:hpid ssje
IF hyid>10000 THEN
UPDATE hyxxb SET knye=knye-ssje,kyjf=kyjf+FLOOR(ssje),scxfsj=NOW() WHERE `hyxxb`.`hyid`=hyid;
END IF;
END