{"id":4118,"date":"2020-11-26T17:47:13","date_gmt":"2020-11-26T09:47:13","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=4118"},"modified":"2026-03-20T10:26:34","modified_gmt":"2026-03-20T02:26:34","slug":"%e5%85%b3%e4%ba%8edecimalps%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e7%9b%b8%e4%b9%98%e4%b8%banull%e7%9a%84%e9%97%ae%e9%a2%98%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=4118","title":{"rendered":"\u5173\u4e8edecimal(p,s)\u6570\u636e\u7c7b\u578b\u76f8\u4e58\u4e3anull\u7684\u95ee\u9898\u8bf4\u660e"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<p><strong>Inceptor \u4e2d DECIMAL(p,s) \u6709\u4e24\u4e2a\u53c2\u6570:<\/strong><\/p>\n<ul>\n<li>p \u4e3a\u7c7b\u578b\u7684\u7cbe\u5ea6(precision):\u5b83\u89c4\u5b9a\u4e86\u8be5 DECIMAL \u7c7b\u578b\u603b\u5171\u53ef\u4ee5\u6709\u591a\u5c11\u4f4d(\u5305\u62ec\u5c0f\u6570\u70b9\u524d\u548c\u5c0f\u6570\u70b9\u540e\u7684\u4f4d)\u3002Inceptor\u4e2d\u7cbe\u5ea6\u6700\u5927\u4e0d\u80fd\u8d85\u8fc738\u3002<\/li>\n<li>s \u4e3a\u7c7b\u578b\u7684\u6807\u5ea6(scale):\u5b83\u89c4\u5b9a\u4e86\u8be5 DECIMAL \u7c7b\u578b\u5c0f\u6570\u70b9\u540e\u9762\u7684\u4f4d\u6570\u3002s \u4e0d\u80fd\u5927\u4e8e p\u3002(decimal\u5217\u7684s\u4e0d\u652f\u6301\u8d1f\u6570, \u4f46\u662f\u53ef\u4ee5\u901a\u8fc7round\u4f20\u5165\u8d1fscale\u6765\u8fbe\u5230\u7c7b\u4f3cOracle\u7684\u6548\u679c,\u4e0d\u8fc7Inceptor\u4e2d\u4f1a\u8ba4\u4e3a\u7ed3\u679c\u662fscale=0\u7684\u4e00\u4e2a\u6570)<\/li>\n<li><strong>\u5982\u679c\u6570\u636e\u65e0\u6cd5\u6309\u7167\u6307\u5b9a\u7684\u7cbe\u5ea6\u548c\u6807\u5ea6\u8868\u793a,\u5c06\u88ab\u8ba4\u4e3a\u662f NULL\u503c\u3002<\/strong><\/li>\n<\/ul>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<h4>1. \u65b0\u5efa\u4e00\u5f20ORC\u666e\u901a\u8868EMP_ORC<\/h4>\n<pre><code class=\"language-sql\">> create table test(v1 decimal(38,20), v2 decimal(38,20));\n> insert into test select 1,2 from system.dual;\n--\u6267\u884c\u7ed3\u679c\u4e3anull\uff0c\u4e0e\u5b9e\u9645\u4e0d\u7b26\n> select v1*v2 from test;   --null<\/code><\/pre>\n<h4>2. \u539f\u7406\u5206\u6790<\/h4>\n<p><strong>\u4e24\u4e2adecimal(p,s)\u6570\u636e\u7c7b\u578b\u76f8\u4e58\uff0cInceptor\u4e2d\u9996\u5148\u6839\u636e\u8f93\u5165\u7684decimal(\u5e38\u91cf\u8868\u8fbe\u5f0f\u6839\u636e\u5b9e\u9645\u6570\u636e\u7684ps,\u5176\u4ed6\u6839\u636e\u5217\u7684ps)\u7684Precision\u548cScale\u8ba1\u7b97\u76ee\u6807Precision\u548cScale\u3002<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u64cd\u4f5c<\/th>\n<th>\u7ed3\u679cPrecision<\/th>\n<th>\u7ed3\u679cScale<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>e1*e2<\/td>\n<td>p1+p2+1<\/td>\n<td>s1+s2<\/td>\n<td>*<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5bf9\u4e8e\u4e58\u6cd5\u8fd0\u7b97,\u5982\u679c\u7b97\u51fa\u6765\u7684Precision\u548cScale\u8d85\u8fc738,\u53ea\u53d6\u523038. \u5373:<\/strong><\/p>\n<ul>\n<li>\u5982\u679cPrecision \u8d85\u8fc738,Scale\u6ca1\u6709\u8d85\u8fc738,\u5219\u76ee\u6807\u7c7b\u578b\u4e3adecimal(38,scale)<\/li>\n<li>\u5982\u679cPrecision\u548cScale\u90fd\u8d85\u8fc738,\u5219\u76ee\u6807\u7c7b\u578b\u4e3adecimal(38,38)<\/li>\n<\/ul>\n<p>*<em>\u4ee5\u4e0b\u9762\u7684\u4f8b\u5b50\u4e3a\u4f8b\uff0c\u4e24\u4e2adecimal(38,20)\u6570\u636e\u7c7b\u578b\u76f8\u4e58\uff0c\u7ed3\u679cPrecision=38+38+1=77\uff0c\u7ed3\u679cScale=20+20=40\uff0cPrecision\u548cScale\u90fd\u8d85\u8fc738\uff0cInceptor\u4f1a\u4f18\u5148\u4fdd\u8bc1Scale\uff0c\u6240\u4ee5\u5b9e\u9645\u63a8\u65ad\u503c\u4e3adecimal(38,38)\uff0c\u800c1<\/em>2=2\uff0c\u65e0\u6cd5\u5b58\u5165decimal(38,38)\uff0c\u8ba4\u4e3a\u8d85\u754c\u62a5\u9519\uff0c\u6240\u4ee5\u4e3anull\u3002**<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848<\/h3>\n<hr \/>\n<h4>\u65b9\u6848\u4e00\uff1aTDH6.0.2\u7248\u672c\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\uff0c\u5728\u6570\u636e\u8d85\u754c\u65f6\u62a5\u9519\u901a\u77e5<\/h4>\n<pre><code class=\"language-sql\">> set inceptor.strict.evaluate=true;   --\u9ed8\u8ba4\u662ffalse,\u8fd9\u662f\u4e4b\u524d\u5df2\u7ecf\u5b58\u5728\u7684\u5f00\u5173\n> set inceptor.decimal.null.check=true;   --\u9ed8\u8ba4\u662ffalse,\u8fd9\u4e2a\u662f\u63a7\u5236Decimal\u62a5\u9519\u7684\u5173\u952e\u5f00\u5173,\u4f46\u662f\u9700\u8981\u4e0a\u9762\u7684\u5f00\u5173\u914d\u5408,\u5426\u5219\u62a5\u9519\u4f1a\u88ab\u541e\u6389<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/09\/image-1601015091776.png\" alt=\"file\" \/><\/p>\n<h4>\u65b9\u6848\u4e8c\uff1a\u901a\u8fc7Floating scale\u6765\u5c3d\u91cf\u4fdd\u5b58\u7ed3\u679c\u7684\u6574\u6570\u90e8\u5206<\/h4>\n<p><strong>\u77ed\u65f6\u95f4\u5185\u6211\u4eec\u53ea\u80fd\u7528Floating scale\u6765workaround\uff0cFloating Scale\u4f1a\u5c3d\u91cf\u4fdd\u5b58\u7ed3\u679c\u7684\u6574\u6570\u90e8\u5206\uff0c\u8be5\u53c2\u6570\u9ed8\u8ba4\u4e3afalse\uff0c\u9700\u8981\u624b\u52a8set\u3002\u540e\u7eed\u5df2\u5b89\u6392\u5f00\u53d1\u8ba1\u5212\uff08Support decimal without precision\/scale like number type in oracle\uff09<\/strong><\/p>\n<pre><code class=\"language-sql\">> set inceptor.floating.scale.decimal=true;<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/09\/image-1601015106630.png\" alt=\"file\" \/><\/p>\n<h3>FAQ<\/h3>\n<p><code>inceptor.floating.scale.decimal<\/code> \u8be5\u53c2\u6570\u5f00\u5173\u6253\u5f00\u4e4b\u540e <code>create table xx as select<\/code> \u8bed\u53e5\u548c <code>with xx as<\/code> \u8bed\u53e5\u53ef\u80fd\u4f1a\u4e0d\u652f\u6301\uff0c\u62a5\u9519 <code>floating scale decimal is not supported<\/code>\uff0c \u89e3\u51b3\u65b9\u6848\u662f \u8981\u4e48\u5728 <code>select<\/code> \u8bed\u53e5\u91cc\u7684\u5bf9\u5e94\u5217\u5916\u9762\u5957\u4e0a<code> cast(xx as decimal(p,s))<\/code>. \u6216\u8005\u76f4\u63a5\u5355\u72ec\u8bed\u53e5\u5efa\u8868,\u628a\u5bf9\u5e94\u5217\u7684\u5b9a\u4e49\u663e\u793a\u7684\u5199\u51fa\u6765 \u3002 \u4e0b\u9762\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-sql\">--\u95ee\u9898\u590d\u73b0\uff1a\ndrop table IF EXISTS t2;\ncreate table t2(a decimal(38,25));\ninsert into t2 select 312.0217 from system.dual;\nselect a*0.476893*0.476893*0.476893 from t2; --NULL\n\nSET inceptor.floating.scale.decimal =TRUE;\n-- \u4e0b\u9762\u7684\u8bed\u53e5\u6267\u884c\u62a5\u9519\uff1ajava.sql.SQLException: COMPILE FAILED: Semantic error: [Error 11371] floating scale decimal is not supported. Column name: _c0, column type: decimal(48,-2147483648)\nCREATE TABLE test0002 AS select a*0.476893*0.476893*0.476893 from t2;\n\n--\u89e3\u51b3\u65b9\u6848\uff1a\n--\u65b9\u6848\u4e00\uff1a\nCREATE TABLE test0002 AS select CAST (a*0.476893*0.476893*0.476893 AS decimal(38,20))from t2;\nSELECT * FROM test0002;\n\n--\u65b9\u6848\u4e8c\uff1a\nDROP TABLE IF EXISTS test0003;\nCREATE TABLE test0003 (DT DECIMAL(38,20));\nINSERT INTO test0003 select a*0.476893*0.476893*0.476893 from t2;\nSELECT * FROM test0003;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 Inceptor \u4e2d DECIMAL(p,s) \u6709\u4e24\u4e2a\u53c2\u6570: p \u4e3a\u7c7b\u578b\u7684\u7cbe\u5ea6(precision) ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=4118\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[165],"class_list":["post-4118","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-decimal"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/4118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4118"}],"version-history":[{"count":4,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/4118\/revisions"}],"predecessor-version":[{"id":12472,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/4118\/revisions\/12472"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}