{"id":5137,"date":"2024-11-14T08:50:00","date_gmt":"2024-11-14T00:50:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5137\/"},"modified":"2024-11-14T08:50:00","modified_gmt":"2024-11-14T00:50:00","slug":"mysql%e6%80%8e%e4%b9%88%e6%b7%bb%e5%8a%a0number","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5137\/","title":{"rendered":"mysql\u600e\u4e48\u6dfb\u52a0number"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u6dfb\u52a0 number \u7c7b\u578b\uff1a\u4f7f\u7528 alter table table_name add column column_name number(precision, scale); \u5176\u4e2d\uff0cprecision \u662f\u6700\u5927\u6570\u5b57\u4f4d\u6570\uff0cscale\u662f\u5c0f\u6570\u70b9\u540e\u4f4d\u6570\uff0c\u5982\u521b\u5efa\u4e00\u4e2a balances \u8868\uff0c\u5305\u542b\u4e00\u4e2a\u7cbe\u5ea6\u4e3a 10\uff0c\u5c0f\u6570\u70b9\u540e 2 \u4f4d\u7684 amount \u5217\uff1acreate table balances (account_id int not null, amount number(10, 2) not n\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052216032351979.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u6dfb\u52a0number\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u6dfb\u52a0number\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u4e2d\u6dfb\u52a0 NUMBER \u7c7b\u578b<\/strong><\/p>\n<p>NUMBER \u6570\u636e\u7c7b\u578b\u7528\u4e8e\u5b58\u50a8\u9ad8\u7cbe\u5ea6\u7684\u5341\u8fdb\u5236\u6570\u5b57\u3002\u5b83\u5728\u91d1\u878d\u3001\u79d1\u5b66\u548c\u5de5\u7a0b\u5e94\u7528\u4e2d\u5f88\u6709\u7528\uff0c\u9700\u8981\u7cbe\u786e\u5b58\u50a8\u548c\u8ba1\u7b97\u5927\u6570\u5b57\u3002<\/p>\n<p><strong>\u6dfb\u52a0 NUMBER \u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>\u8981\u5411 MySQL \u8868\u4e2d\u6dfb\u52a0 NUMBER \u6570\u636e\u7c7b\u578b\u5217\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>ALTER TABLE table_name ADD COLUMN column_name NUMBER(precision, scale);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name \u662f\u8981\u6dfb\u52a0\u5217\u7684\u8868\u540d<\/li>\n<li>column_name \u662f\u8981\u6dfb\u52a0\u7684\u5217\u540d<\/li>\n<li>precision \u662f\u5217\u4e2d\u53ef\u4ee5\u5b58\u50a8\u7684\u6700\u5927\u6570\u5b57\u4f4d\u6570\uff08\u5305\u62ec\u5c0f\u6570\u70b9\uff09<\/li>\n<li>scale \u662f\u5217\u4e2d\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a balances \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a amount \u5217\u6765\u5b58\u50a8\u5e10\u6237\u4f59\u989d\uff1a<\/p>\n<pre>CREATE TABLE balances (\n  account_id INT NOT NULL,\n  amount NUMBER(10, 2) NOT NULL\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u793a\u4f8b\u521b\u5efa\u4e00\u4e2a amount \u5217\uff0c\u5176\u7cbe\u5ea6\u4e3a 10\uff0c\u5c0f\u6570\u70b9\u540e 2 \u4f4d\u3002\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u5b58\u50a8\u6700\u5927 10 \u4f4d\u6570\u5b57\uff08\u5305\u62ec\u5c0f\u6570\u70b9\uff09\uff0c\u5c0f\u6570\u70b9\u540e\u6700\u591a 2 \u4f4d\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>precision \u548c scale \u5fc5\u987b\u662f\u6574\u6570\u3002<\/li>\n<li>precision \u4e0d\u80fd\u5c0f\u4e8e scale\u3002<\/li>\n<li>MySQL 8.0 \u53ca\u66f4\u9ad8\u7248\u672c\u652f\u6301 NUMBER \u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u6dfb\u52a0number\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql \u4e2d\u6dfb\u52a0 number \u7c7b\u578b\uff1a\u4f7f\u7528 alter table table_name add column column_name number(precision, scale); \u5176\u4e2d\uff0cprecision \u662f\u6700\u5927\u6570\u5b57\u4f4d\u6570\uff0cscale\u662f\u5c0f\u6570\u70b9\u540e\u4f4d\u6570\uff0c\u5982\u521b\u5efa\u4e00\u4e2a balances \u8868\uff0c\u5305\u542b\u4e00\u4e2a\u7cbe\u5ea6\u4e3a 10\uff0c\u5c0f\u6570\u70b9\u540e 2 \u4f4d\u7684 amount \u5217\uff1acreate table balances (account_id int not null, amount number(10, 2) not n \u5982\u4f55\u5728 MySQL \u4e2d\u6dfb\u52a0 NUMBER \u7c7b\u578b NUMBER \u6570\u636e\u7c7b\u578b\u7528\u4e8e\u5b58\u50a8\u9ad8\u7cbe\u5ea6\u7684\u5341\u8fdb\u5236\u6570\u5b57\u3002\u5b83\u5728\u91d1\u878d\u3001\u79d1\u5b66\u548c\u5de5\u7a0b\u5e94\u7528\u4e2d\u5f88\u6709\u7528\uff0c\u9700\u8981\u7cbe\u786e\u5b58\u50a8\u548c\u8ba1\u7b97\u5927\u6570\u5b57\u3002 \u6dfb\u52a0 NUMBER \u6570\u636e\u7c7b\u578b \u8981\u5411 MySQL \u8868\u4e2d\u6dfb\u52a0 NUMBER \u6570\u636e\u7c7b\u578b\u5217\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a ALTER TABLE table_name ADD COLUMN column_name NUMBER(precision, scale); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5137","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5137"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5137\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}