{"id":4831,"date":"2024-03-19T12:49:36","date_gmt":"2024-03-19T03:49:36","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=4831"},"modified":"2024-02-21T12:58:45","modified_gmt":"2024-02-21T03:58:45","slug":"post-4831","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/4831","title":{"rendered":"MySQL\u3067\u30b9\u30c8\u30a2\u30c9\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u623b\u308a\u5024\u5bfe\u5fdc\u7248\u3067\u3042\u308b\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3068\u5229\u7528\u65b9\u6cd5"},"content":{"rendered":"<p>\u5148\u65e5MySQL\u306e\u30b9\u30c8\u30a2\u30c9\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306b\u95a2\u3059\u308b\u30e1\u30e2\u3092\u66f8\u3044\u305f\u304c\u3001\u4eca\u56de\u306f\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306b\u3064\u3044\u3066\u3082\u8272\u3005\u8a66\u3057\u3066\u307f\u305f\u3044\u3002\u3056\u3063\u3068\u8abf\u3079\u305f\u3068\u3053\u308d\u57fa\u672c\u7684\u306b\u306f\u4e00\u9023\u306e\u51e6\u7406\u3092\u767b\u9332\u3057\u3066\u304a\u304f\u3068\u95a2\u6570\u307f\u305f\u3044\u306b\u4f7f\u3048\u308b\u3001\u3068\u30b9\u30c8\u30a2\u30c9\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u540c\u3058\u3063\u307d\u3044\u304c\u3001\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306f\u623b\u308a\u5024\u304c\u3042\u308b\u307f\u305f\u3044\u3002\u4ee5\u4e0b\u306b\u8a2d\u5b9a\u3092\u5229\u7528\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"i\">\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/span><\/h2>\n<p>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u3092\u53c2\u7167\u3002<\/p>\n<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/ja\/create-procedure.html\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/ja\/create-procedure.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"i-2\">\u4e8b\u524d\u6e96\u5099<\/span><\/h2>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u53ca\u3073\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3057\u305f\u3002<\/p>\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| score      | int          | NO   |     | NULL    |                |\r\n| regist_ymd | datetime     | NO   |     | NULL    |                |\r\n+------------+--------------+------+-----+---------+----------------+\r\n\r\nmysql&gt; SELECT * FROM `test_table`;\r\n+----+-----------+-------+---------------------+\r\n| id | name      | score | regist_ymd          |\r\n+----+-----------+-------+---------------------+\r\n|  1 | \u9234\u6728      |    80 | 2024-02-15 18:13:49 |\r\n|  2 | \u4f50\u3005\u6728    |    70 | 2024-02-15 18:20:11 |\r\n|  3 | \u5c71\u7530      |    50 | 2024-02-21 12:47:20 |\r\n+----+-----------+-------+---------------------+<\/pre>\n<p>&nbsp;<\/p>\n<h2><span id=\"i-3\">\u8a2d\u5b9a\u65b9\u6cd5<\/span><\/h2>\n<h3><span id=\"i-4\">\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306e\u8ffd\u52a0<\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">DELIMITER \/\/\r\nCREATE FUNCTION test_function() RETURNS DOUBLE DETERMINISTIC\r\nBEGIN \r\n    DECLARE avg_score DOUBLE;\r\n    SELECT AVG(`score`) INTO avg_score FROM `test_table`;\r\n    RETURN avg_score;\r\nEND\r\n\/\/\r\nDELIMITER ;<\/pre>\n<p>\u5168score(\u70b9\u6570)\u306e\u5e73\u5747\u5024\u3092\u8fd4\u3059\u3068\u3044\u3046\u5185\u5bb9\u306b\u306a\u308b\u3002<\/p>\n<h3><span id=\"i-5\">\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306e\u78ba\u8a8d<\/span><\/h3>\n<p>\u6b63\u5e38\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u304b\u306f\u4ee5\u4e0b\u3067\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SHOW CREATE FUNCTION test_function;<\/pre>\n<h3><span id=\"i-6\">\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306e\u5b9f\u884c<\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mysql&gt; SELECT test_function();\r\n+-----------------+\r\n| test_function() |\r\n+-----------------+\r\n|    66.666666666 |\r\n+-----------------+<\/pre>\n<h3><span id=\"i-7\">\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306e\u524a\u9664<\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">DROP FUNCTION test_function;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u65e5MySQL\u306e\u30b9\u30c8\u30a2\u30c9\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306b\u95a2\u3059\u308b\u30e1\u30e2\u3092\u66f8\u3044\u305f\u304c\u3001\u4eca\u56de\u306f\u30b9\u30c8\u30a2\u30c9\u30d5\u30a1\u30f3 ... <\/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-4831","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\/4831","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=4831"}],"version-history":[{"count":5,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4831\/revisions"}],"predecessor-version":[{"id":4834,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4831\/revisions\/4834"}],"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=4831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=4831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=4831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}