{"id":6700,"date":"2024-11-30T10:43:34","date_gmt":"2024-11-30T01:43:34","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6700"},"modified":"2024-08-29T16:41:30","modified_gmt":"2024-08-29T07:41:30","slug":"post-6700","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6700","title":{"rendered":"MySQL\u306b\u3066\u6307\u5b9a\u3057\u305f\u30ab\u30e9\u30e0\u304cNULL\u3082\u3057\u304f\u306f\u7a7a\u306e\u5834\u5408\u3001\u3042\u3089\u304b\u3058\u3081\u6c7a\u3081\u3066\u304a\u3044\u305f\u5185\u5bb9\u3067\u8868\u793a\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u4f55\u3089\u304b\u306e\u30d5\u30a9\u30fc\u30e0\u3068MySQL\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u969b\u306b\u4efb\u610f\u5165\u529b\u306e\u9805\u76ee\u306f\u305d\u306e\u30ab\u30e9\u30e0\u304cNULL\u3082\u3057\u304f\u306f\u7a7a\u306b\u306a\u308b\u3002\u305d\u306e\u30c7\u30fc\u30bf\u3092\u7ba1\u7406\u753b\u9762\u7b49\u3067\u8868\u793a\u3059\u308b\u969b\u3001NULL\u3082\u3057\u304f\u306f\u7a7a\u306e\u30c7\u30fc\u30bf\u306fPHP\u5074\u3067\u5224\u5b9a\u3057\u300c\u672a\u5165\u529b\u300d\u306e\u3088\u3046\u306b\u8868\u793a\u3057\u3066\u3044\u305f\u304c\u3001\u3053\u306e\u8fba\u308a\u3092MySQL\u5074\u3067\u5bfe\u5fdc\u3057\u305f\u3044\u3002\u4ee5\u4e0b\u306b\u5bfe\u5fdc\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"i\">\u30c6\u30fc\u30d6\u30eb\u69cb\u9020\u3068\u30c7\u30fc\u30bf\u5185\u5bb9<\/span><\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mysql&gt; SHOW COLUMNS FROM `test_table`;\r\n+-------+--------------+------+-----+---------+----------------+\r\n| Field | Type         | Null | Key | Default | Extra          |\r\n+-------+--------------+------+-----+---------+----------------+\r\n| id    | int          | NO   | PRI | NULL    | auto_increment |\r\n| name  | varchar(255) | NO   |     | NULL    |                |\r\n| job   | varchar(255) | YES  |     | NULL    |                |\r\n+-------+--------------+------+-----+---------+----------------+\r\n\r\nmysql&gt; SELECT * FROM `test_table`;\r\n+----+-----------+-----------+\r\n| id | name      | job       |\r\n+----+-----------+-----------+\r\n|  1 | \u7530\u4e2d      | \u4f1a\u793e\u54e1    |\r\n|  2 | \u9234\u6728      | NULL      |\r\n|  3 | \u4f50\u3005\u6728    | \u81ea\u55b6\u696d    |\r\n|  4 | \u5c71\u7530      | NULL      |\r\n|  5 | \u658e\u85e4      |           |\r\n+----+-----------+-----------+<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u5bfe\u5fdc\u65b9\u6cd5<\/h2>\n<h3>\u7a7a\u306e\u30ab\u30e9\u30e0\u306f\u5b58\u5728\u3057\u306a\u3044(NULL\u3060\u3051\u306e\u5224\u5b9a\u3067\u3044\u3044)\u5834\u5408<\/h3>\n<p>\u7a7a\u306e\u30ab\u30e9\u30e0\u306f\u6c17\u306b\u305b\u305a\u3001NULL\u3060\u3051\u5224\u5b9a\u3057\u6307\u5b9a\u3057\u305f\u5185\u5bb9\u3092\u8868\u793a\u3055\u305b\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306eSQL\u6587\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SELECT `name`, COALESCE(`job`, '\u672a\u767b\u9332') AS job \r\nFROM `test_table`;<\/pre>\n<p>\u305f\u3060\u3001\u7a7a\u306e\u30ab\u30e9\u30e0\u304c\u5b58\u5728\u3057\u3066\u3044\u308b\u3068\u305d\u306e\u307e\u307e\u7a7a\u3068\u3057\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">+-----------+-----------+\r\n| name      | job       |\r\n+-----------+-----------+\r\n| \u7530\u4e2d      | \u4f1a\u793e\u54e1    |\r\n| \u9234\u6728      | \u672a\u767b\u9332    |\r\n| \u4f50\u3005\u6728    | \u81ea\u55b6\u696d    |\r\n| \u5c71\u7530      | \u672a\u767b\u9332    |\r\n| \u658e\u85e4      |           |\r\n+-----------+-----------+<\/pre>\n<h3>\u7a7a\u3082NULL\u3082\u5224\u5b9a\u3059\u308b\u5834\u5408<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SELECT `name`, \r\n    CASE \r\n        WHEN `job` IS NULL OR `job` = '' THEN '\u672a\u767b\u9332' \r\n        ELSE `job` \r\n    END AS `job` \r\nFROM `test_table`;\r\n\r\n+-----------+-----------+\r\n| name      | job       |\r\n+-----------+-----------+\r\n| \u7530\u4e2d      | \u4f1a\u793e\u54e1    |\r\n| \u9234\u6728      | \u672a\u767b\u9332    |\r\n| \u4f50\u3005\u6728    | \u81ea\u55b6\u696d    |\r\n| \u5c71\u7530      | \u672a\u767b\u9332    |\r\n| \u658e\u85e4      | \u672a\u767b\u9332    |\r\n+-----------+-----------+<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f55\u3089\u304b\u306e\u30d5\u30a9\u30fc\u30e0\u3068MySQL\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u969b\u306b\u4efb\u610f\u5165\u529b\u306e\u9805\u76ee\u306f\u305d\u306e\u30ab\u30e9\u30e0\u304cNUL ... <\/p>\n","protected":false},"author":1,"featured_media":1072,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5,66],"tags":[],"class_list":["post-6700","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","category-database"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6700"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6700\/revisions"}],"predecessor-version":[{"id":6701,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6700\/revisions\/6701"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1072"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}