<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/post//</link>
<title><![CDATA[mysql ifnul decimal变成四舍五入保留一位小数的问题]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[数据库]]></category>
<pubDate>Mon, 18 Oct 2021 07:33:21 +0000</pubDate> 
<guid>https://www.heckjj.com/post//</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;最近在维护一个几年前的项目，发现供应商报价本来为decimal类型保留两位小数的数据，结果通过ifnull后变成四舍五入保小一位小数了，排查了很久才现是由于ifnull函数引起的问题。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/> SELECT<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IFNULL( (select CREATION_DATE&nbsp;&nbsp;from&nbsp;&nbsp;pur_bidding_supplier_line pbsl where&nbsp;&nbsp;pbsh.HEAD_ID = pbsl.HEAD_ID&nbsp;&nbsp;order by CREATION_DATE desc LIMIT 1 ) ,&nbsp;&nbsp;pbsh.CREATION_DATE) as CREATION_DATE,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IFNULL((select LINE_ID&nbsp;&nbsp;from&nbsp;&nbsp;pur_bidding_supplier_line pbsl where&nbsp;&nbsp;pbsh.HEAD_ID = pbsl.HEAD_ID&nbsp;&nbsp;order by CREATION_DATE desc LIMIT 1 ) ,0) as LINE_ID,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #FF0000;">CONVERT(</span>IFNULL((select QUOTED_PRICE&nbsp;&nbsp;from&nbsp;&nbsp;pur_bidding_supplier_line pbsl where&nbsp;&nbsp;pbsh.HEAD_ID = pbsl.HEAD_ID&nbsp;&nbsp;order by CREATION_DATE desc LIMIT 1 ),99999999999999999999999)<span style="color: #FF0000;">,decimal(20,2))</span> as QUOTED_PRICE,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbsh.SUPPLIER_ID,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ps.SUPPLIER_NAME,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pe.PRO_ID ,<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( select glook from pur_program&nbsp;&nbsp;p&nbsp;&nbsp;where p.pro_id=pe.PRO_ID) as GLOOK,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( select AGENTLOOK from&nbsp;&nbsp;pur_program&nbsp;&nbsp; p where p.pro_id=pe.PRO_ID) as AGENTLOOK<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pur_bidding_supplier_head pbsh,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pur_evaluation pe,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pur_supplier ps<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pe.EVALUATION_ID = pbsh.EVALUATION_ID<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND ps.SUPPLIER_ID = pbsh.SUPPLIER_ID<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND pe.PRO_ID = #&#123;0&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ORDER BY<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbsh.CREATION_DATE DESC<br/><br/>最后通过上面红色部分的convert函数来实现转成保留两位小数。<br/>转换前的数据<br/>2021-07-06 10:43:00&nbsp;&nbsp;26506&nbsp;&nbsp;88889.0&nbsp;&nbsp;6302&nbsp;&nbsp;李盛超测试<br/>2021-07-06 10:47:06&nbsp;&nbsp;26518&nbsp;&nbsp;1500.1&nbsp;&nbsp;6306&nbsp;&nbsp;黄彤测试账号<br/>2021-07-06 10:43:00&nbsp;&nbsp;26508&nbsp;&nbsp;6666.1&nbsp;&nbsp;6304&nbsp;&nbsp;顾志坚测试账号<br/><br/>转换后的数据<br/>2021-07-06 10:43:00&nbsp;&nbsp;26506&nbsp;&nbsp;88889.02&nbsp;&nbsp;6302&nbsp;&nbsp;李盛超测试<br/>2021-07-06 10:47:06&nbsp;&nbsp;26518&nbsp;&nbsp;1500.08&nbsp;&nbsp;6306&nbsp;&nbsp;黄彤测试账号<br/>2021-07-06 10:43:00&nbsp;&nbsp;26508&nbsp;&nbsp;6666.05&nbsp;&nbsp;6304&nbsp;&nbsp;顾志坚测试账号<br/><br/>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/post//#blogcomment</link>
<title><![CDATA[[评论] mysql ifnul decimal变成四舍五入保留一位小数的问题]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>