{"id":2733,"date":"2021-01-04T14:40:13","date_gmt":"2021-01-04T06:40:13","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=2733"},"modified":"2021-01-04T14:40:14","modified_gmt":"2021-01-04T06:40:14","slug":"gbase-8a%e6%97%b6%e9%97%b4%e8%bd%ac%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%b1%bb%e5%9e%8b%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/2733","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u65f6\u95f4\u8f6c\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u51e0\u79cd\u65b9\u6cd5"},"content":{"rendered":"<p>GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\uff0c\u53ef\u4ee5\u901a\u8fc7to_char\u51fd\u6570\uff0cdate_format\u51fd\u6570\uff0c\u4ee5\u53cacast,\u7b49\u51fd\u6570\u4ece\u65e5\u671f\u8f6c\u6210\u5b57\u7b26\u4e32\uff0c\u672c\u6587\u4ecb\u7ecd\u5404\u4e2a\u51fd\u6570\u7684\u5199\u6cd5\u548c\u6837\u4f8b\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2b16339dc1d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2b16339dc1d\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/2733\/#date_format\" >date_format<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/2733\/#to_char\" >to_char<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/2733\/#cast_convert\" >cast \/ convert<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"date_format\"><\/span>date_format<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5982\u4e0b\u662fdete_format\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5b57\u7b26\u4e32\u683c\u5f0f\u5b8c\u5168\u81ea\u5b9a\u4e49\u3002<\/p>\n\n\n\n<p>\u8be6\u60c5\u53ef\u4ee5\u53c2\u8003 <a href=\"https:\/\/www.gbase8.cn\/en\/917\/\">GBase 8a\u6570\u636e\u5e93\u51fd\u6570date_format\u5c06\u65e5\u671f\u683c\u5f0f\u5316\u6210\u6307\u5b9a\u683c\u5f0f\u7684\u6587\u672c<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table a1 as select date_format(now(),'%Y-%m-%d %H:%i:%s') d from dual;\r\nQuery OK, 1 row affected (Elapsed: 00:00:00.26)\r\n\r\ngbase> desc a1;\r\n+-------+-------------+------+-----+---------+-------+\r\n| Field | Type        | Null | Key | Default | Extra |\r\n+-------+-------------+------+-----+---------+-------+\r\n| d     | varchar(24) | YES  |     | NULL    |       |\r\n+-------+-------------+------+-----+---------+-------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n\r\ngbase> select * from a1;\r\n+---------------------+\r\n| d                   |\r\n+---------------------+\r\n| 2021-01-04 14:32:11 |\r\n+---------------------+\r\n1 row in set (Elapsed: 00:00:00.01)\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"to_char\"><\/span>to_char<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5b8c\u5168\u4e0eOracle\u8bed\u6cd5\u517c\u5bb9\u7684\u5199\u6cd5\uff0c\u81ea\u5b9a\u4e49\u683c\u5f0f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table a2 as select to_char(now(),'yyyy-mm-dd') d from dual;\r\nQuery OK, 1 row affected (Elapsed: 00:00:00.28)\r\n\r\ngbase> select * from a1;\r\n+------------+\r\n| d          |\r\n+------------+\r\n| yyyy-mm-dd |\r\n+------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n\r\ngbase> select * from a2;\r\n+------------+\r\n| d          |\r\n+------------+\r\n| 2021-01-04 |\r\n+------------+\r\n1 row in set (Elapsed: 00:00:00.01)\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"cast_convert\"><\/span>cast \/ convert<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u672c\u65b9\u6cd5\u53ea\u662f\u7c7b\u578b\u5f3a\u5236\u8f6c\u6362\uff0c\u5176\u5b57\u7b26\u4e32\u683c\u5f0f\u53d6\u51b3\u4e8e\u9ed8\u8ba4\u7684\u65e5\u671f\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>\u6709\u5173cast\/convert\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u8bf7\u53c2\u8003 <\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u8001\u7d2b\u7af9\u7684\u5bb6 wp-block-embed-\u8001\u7d2b\u7af9\u7684\u5bb6\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"XYcduHnx4W\"><a href=\"https:\/\/www.gbase8.cn\/en\/2653\/\">GBase 8a\u7684\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362cast\u548cconvert\u7684\u7528\u6cd5\u4f8b\u5b50<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"\u300aGBase 8a\u7684\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362cast\u548cconvert\u7684\u7528\u6cd5\u4f8b\u5b50\u300b\u2014\u8001\u7d2b\u7af9\u7684\u5bb6\" src=\"https:\/\/www.gbase8.cn\/2653\/embed#?secret=XYcduHnx4W\" data-secret=\"XYcduHnx4W\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> create table a3 as select cast(now() as char) d from dual;\r\nQuery OK, 1 row affected (Elapsed: 00:00:00.27)\r\n\r\ngbase> desc a3;\r\n+-------+-------------+------+-----+---------+-------+\r\n| Field | Type        | Null | Key | Default | Extra |\r\n+-------+-------------+------+-----+---------+-------+\r\n| d     | varchar(19) | YES  |     | NULL    |       |\r\n+-------+-------------+------+-----+---------+-------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n\r\ngbase> select * from a3;\r\n+---------------------+\r\n| d                   |\r\n+---------------------+\r\n| 2021-01-04 14:38:49 |\r\n+---------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n\r\ngbase> show variables like '%datetime%';\r\n+-----------------+-------------------+\r\n| Variable_name   | Value             |\r\n+-----------------+-------------------+\r\n| datetime_format | %Y-%m-%d %H:%i:%s |\r\n+-----------------+-------------------+\r\n1 row in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\uff0c\u53ef\u4ee5\u901a\u8fc7to_char\u51fd\u6570\uff0cdate_format\u51fd\u6570\uff0c\u4ee5\u53cacast,\u7b49\u51fd\u6570\u4ece\u65e5\u671f\u8f6c\u6210\u5b57\u7b26\u4e32\uff0c\u672c\u6587\u4ecb\u7ecd\u5404\u4e2a\u51fd\u6570\u7684\u5199\u6cd5\u548c\u6837\u4f8b<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[36],"class_list":["post-2733","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-36"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=2733"}],"version-history":[{"count":1,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2733\/revisions"}],"predecessor-version":[{"id":2740,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2733\/revisions\/2740"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=2733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=2733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=2733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}