{"id":4955,"date":"2024-10-04T20:01:06","date_gmt":"2024-10-04T12:01:06","guid":{"rendered":""},"modified":"2024-10-04T20:01:06","modified_gmt":"2024-10-04T12:01:06","slug":"sql\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u56db\u820d\u4e94\u5165\u6cd5_oracle\u600e\u4e48\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570","status":"publish","type":"post","link":"https:\/\/mushiming.com\/4955.html","title":{"rendered":"sql\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u56db\u820d\u4e94\u5165\u6cd5_oracle\u600e\u4e48\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570"},"content":{"rendered":"

1. ROUND(\u8be5\u51fd\u6570\uff0c\u53ea\u662f\u8d1f\u8d23\u56db\u820d\u4e94\u5165\u5230\u4e24\u4f4d\u5c0f\u6570\uff0c\u4f46\u662f\u4e0d\u8d1f\u8d23\u622a\u65ad \u53ea\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u4f8b\u5982\u4e0b\u4f8b\uff1a)<\/p>\n

\u5173\u4e8eROUND\u51fd\u6570\uff0c\u6211\u4eec\u5e73\u5e38\u7406\u89e3\u4e3a4\u820d5\u5165\uff0c\u5982\uff1a<\/p>\n

print ROUND(13.145, 2);<\/p>\n

\u7ed3\u679c\u4e3a\uff1a13.150<\/p>\n

<\/p>\n

 \u5982\u679c\u4fdd\u5b58\u4e3aint ROUND(\u4f60\u7684\u5b57\u6bb5, 0)\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4fdd\u7559\u4f4d\u6570\uff0c0\u662f\u4e2a\u4f4d\uff0c-1\u662f\u5341\u4f4d\uff0c-2\u662f\u767e\u4f4d\uff0c1\u662f\u4fdd\u7559\u4e00\u4f4d\u5c0f\u6570\uff0c2\u662f\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u4e00\u6b21\u7c7b\u63a8<\/span>
<\/p>\n

<\/p>\n

\n

\u65b9\u6cd52\uff1a
<\/span>
SELECT CAST('123.456' as decimal) \u5c06\u4f1a\u5f97\u5230 123\uff08\u5c0f\u6570\u70b9\u540e\u9762\u7684\u5c06\u4f1a\u88ab\u7701\u7565\u6389\uff09\u3002
\u5982\u679c\u5e0c\u671b\u5f97\u5230\u5c0f\u6570\u70b9\u540e\u9762\u7684\u4e24\u4f4d\u3002
\u5219\u9700\u8981\u628a\u4e0a\u9762\u7684\u6539\u4e3a
SELECT CAST('123.456' as decimal(38, 2)) ===>123.46<\/span><\/p>\n

\u8bf4\u660e1:<\/span><\/span><\/p>\n

\u8fd9\u91cc\u7684decimal\u82f1\u6587\u4e3a: \u5c0f\u6570, \u5341\u8fdb\u5236
decimal(38,2)
\u8fd9\u91cc\u768438\u662f\u8fd9\u4e2a\u5c0f\u6570\u7684\u4f4d\u6570\u6709\u591a\u5c11\u4f4d, \u4e00\u822c\u6700\u5927\u4e0d\u8d85\u8fc738\u4f4d, \u6240\u4ee5\u519938\u662f\u4e0d\u4f1a\u51fa\u9519\u7684!
\u5982\u679c:
SELECT CAST('123.456' as decimal(2, 2))
\u5c31\u4f1a\u51fa\u9519, \u4e3a\u4ec0\u4e48\u5462, \u56e0\u4e3a\u8fd9\u4e2a123.456\u5c0f\u6570\u70b9\u540e\u662f3\u4f4d\u503c, \u6240\u4ee5\u8fd9\u4e2a38\u8fd9\u4e2a\u4f4d\u7f6e\u6700\u5c11\u662f3!<\/span><\/p>\n

\u8bf4\u660e2:<\/span>
decimal\u540e\u9762\u7684\u53c2\u6570\u4e2d\u76842\u662f\u5c0f\u6570\u70b9\u540e\u53d6\u51e0\u4f4d, \u662f2\u5c31\u53d6\u4e24\u4f4d, \u662f3\u5c31\u53d6\u4e09\u4f4d! \u5e76\u4e14\u662f\u56db\u820d\u4e94\u5165\u540e\u7684\u7ed3\u679c!<\/span><\/p>\n

\u8bf4\u660e3:<\/span>
cast\u5e94\u8be5\u5c31\u662f\u8f6c\u6362\u6570\u503c\u7684\u610f\u601d\u4e86<\/span><\/p>\n


\u81ea\u52a8\u56db\u820d\u4e94\u5165\u4e86\uff01<\/span><\/p>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"sql\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u56db\u820d\u4e94\u5165\u6cd5_oracle\u600e\u4e48\u4fdd\u7559\u4e24\u4f4d\u5c0f\u65701.ROUND(\u8be5\u51fd\u6570\uff0c\u53ea\u662f\u8d1f\u8d23\u56db\u820d\u4e94\u5165\u5230\u4e24\u4f4d\u5c0f\u6570\uff0c\u4f46\u662f\u4e0d\u8d1f\u8d23\u622a\u65ad\u53ea\u7559\u4e24\u4f4d\u5c0f...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/4955"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=4955"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/4955\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=4955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=4955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=4955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}