{"id":4723,"date":"2018-06-21T03:08:39","date_gmt":"2018-06-20T18:08:39","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=4723"},"modified":"2023-05-27T23:19:51","modified_gmt":"2023-05-27T14:19:51","slug":"%e3%80%90oracle%e3%80%91sql%e3%81%ae%e9%96%a2%e6%95%b0%e4%b8%80%e8%a6%a7","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=4723","title":{"rendered":"\u3010SQL\u3011\u95a2\u6570\u4e00\u89a7"},"content":{"rendered":"<p>SQL\u306e\u95a2\u6570\u306f\u5927\u304d\u304f\u4e0b\u8a18\u306e\u7a2e\u985e\u306b\u5206\u304b\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u7b97\u8853\u95a2\u6570\uff08\u6570\u5024\u8a08\u7b97\u306e\u305f\u3081\u306e\u95a2\u6570\uff09<\/li>\n<li>\u6587\u5b57\u5217\u95a2\u6570\uff08\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u305f\u3081\u306e\u95a2\u6570\uff09<\/li>\n<li>\u65e5\u4ed8\u95a2\u6570\uff08\u65e5\u4ed8\u64cd\u4f5c\u306e\u305f\u3081\u306e\u95a2\u6570\uff09<\/li>\n<li>\u5909\u63db\u95a2\u6570\uff08\u30c7\u30fc\u30bf\u578b\u3084\u3001\u5024\u3092\u5909\u63db\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff09<\/li>\n<li>\u96c6\u7d04\u95a2\u6570\uff08\u30c7\u30fc\u30bf\u96c6\u8a08\u306e\u305f\u3081\u306e\u95a2\u6570\uff09<\/li>\n<\/ul>\n<h2>\u7b97\u8853\u95a2\u6570\uff08\u6570\u5024\u8a08\u7b97\u306e\u305f\u3081\u306e\u95a2\u6570\uff09<\/h2>\n<h3>MOD\u95a2\u6570<\/h3>\n<p>\u4f59\u308a\u3092\u6c42\u3081\u308b\u95a2\u6570<\/p>\n<h3>ROUND\u95a2\u6570<\/h3>\n<p>\u56db\u6368\u4e94\u5165\u3059\u308b\u95a2\u6570<\/p>\n<h2>\u65e5\u4ed8\u95a2\u6570\uff08\u65e5\u4ed8\u64cd\u4f5c\u306e\u305f\u3081\u306e\u95a2\u6570\uff09<\/h2>\n<h3>CURRENT_DATE<\/h3>\n<p>\u73fe\u5728\u306e\u65e5\u4ed8\u3092\u53d6\u5f97\u3059\u308b\u3002<\/p>\n<h2>\u6587\u5b57\u5217\u95a2\u6570<\/h2>\n<h3>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf<\/h3>\n<table style=\"border-collapse: collapse; width: 162pt;\" border=\"0\" width=\"216\" cellspacing=\"0\" cellpadding=\"0\">\n<colgroup>\n<col style=\"width: 54pt;\" span=\"3\" width=\"72\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 13.5pt;\">\n<th style=\"height: 13.5pt; width: 54pt;\" width=\"72\" height=\"18\">USER_ID<\/th>\n<th style=\"width: 54pt;\" width=\"72\">DEPT_NO<\/th>\n<th style=\"width: 54pt;\" width=\"72\">USER_NAME<\/th>\n<\/tr>\n<tr style=\"height: 13.5pt;\">\n<td style=\"height: 13.5pt;\" align=\"right\" height=\"18\">21<\/td>\n<td align=\"right\">1002<\/td>\n<td>\u5c0f\u6cc9 \u7d14\u5b50<\/td>\n<\/tr>\n<tr style=\"height: 13.5pt;\">\n<td style=\"height: 13.5pt;\" align=\"right\" height=\"18\">22<\/td>\n<td align=\"right\">1003<\/td>\n<td>\u5c0f\u6cc9 \u4e09\u90ce<\/td>\n<\/tr>\n<tr style=\"height: 13.5pt;\">\n<td style=\"height: 13.5pt;\" align=\"right\" height=\"18\">23<\/td>\n<td align=\"right\">1004<\/td>\n<td>\u5c0f\u6cc9 \u82b1\u5b50<\/td>\n<\/tr>\n<tr style=\"height: 13.5pt;\">\n<td style=\"height: 13.5pt;\" align=\"right\" height=\"18\">20<\/td>\n<td align=\"right\">1001<\/td>\n<td>\u5c0f\u6cc9 \u7d14\u4e00<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u6587\u5b57\u5217\u95a2\u6570\uff08\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u305f\u3081\u306e\u95a2\u6570\uff09<\/h3>\n<h4>\u300c||\u300d(SQLServer\u3068MySQL\u3067\u306f\u4f7f\u3048\u306a\u3044\u3002)<\/h4>\n<p>\u6587\u5b57\u5217\u3092\u9023\u7d50\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n<h5>SQL<\/h5>\n<pre class=\"lang:default decode:true\">select '\u30e6\u30fc\u30b6\u30fcID' || DEPT_NO || '\u306f' || USER_NAME || '\u3067\u3059\u3002' AS INSTRODUCTION from user_master<\/pre>\n<h5>\u5b9f\u884c\u7d50\u679c<\/h5>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-5281\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/\u6587\u5b57\u5217\u9023\u7d50_\u5b9f\u884c\u7d50\u679c.png\" alt=\"\" width=\"235\" height=\"124\" \/><\/p>\n<h4>LENGTH(SQLServer\u3067\u306f\u4f7f\u3048\u306a\u3044\u3002)<\/h4>\n<p>\u6587\u5b57\u5217\u9577\u3092\u6c42\u3081\u308b\u95a2\u6570<\/p>\n<h4>LOWER<\/h4>\n<p>\u5c0f\u6587\u5b57\u5316\u3055\u305b\u308b\u3002<\/p>\n<h4>UPPER<\/h4>\n<p>\u5927\u6587\u5b57\u5316\u3055\u305b\u308b\u3002<\/p>\n<h4>REPLACE<\/h4>\n<p>\u6587\u5b57\u5217\u7f6e\u63db\u3059\u308b\u3002<\/p>\n<h4>SUBSTRING<\/h4>\n<p>\u6587\u5b57\u5217\u304b\u3089\u3001\u7279\u5b9a\u306e\u6587\u5b57\u3092\u5207\u308a\u51fa\u3059\u3002<\/p>\n<h2>\u5909\u63db\u95a2\u6570\uff08\u30c7\u30fc\u30bf\u578b\u3084\u5024\u3092\u5909\u63db\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff09<\/h2>\n<h3>COALESCE\u95a2\u6570<\/h3>\n<p>NULL\u5024\u3092\u5024\u3078\u5909\u63db\u3059\u308b\u3002<\/p>\n<h3>NVL\u95a2\u6570(Oracle\u306e\u307f)<\/h3>\n<p>NULL\u306e\u5024\u3092\u5225\u306e\u5024\u306b\u7f6e\u304d\u63db\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">SELECT NVL(NAME,'\u540d\u524d\u306a\u3057') FROM ITEM<\/pre>\n<h3>DECODE\u95a2\u6570(Oracle\u306e\u307f)<\/h3>\n<p>NULL\u304b\u3001NULL\u4ee5\u5916\u304b\u3067\u5024\u3092\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">SELECT DECODE(NAME,NULL,'\u540d\u524d\u767b\u9332\u3042\u308a','\u540d\u524d\u767b\u9332\u306a\u3057')\r\nFROM ITEM<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>CASE\u6587\u3092\u4f7f\u3046\u5834\u5408\u3068\u305d\u308c\u307b\u3069\u5b9f\u884c\u901f\u5ea6\u306f\u5909\u308f\u3089\u306a\u3044<\/strong><\/span>\u306e\u3067\u4f7f\u3044\u5206\u3051\u306f\u304a\u597d\u307f\u306e\u3088\u3046\u3067\u3059\u304c\u3001DECODE\u95a2\u6570\u306f\u3001Oracle\u3067\u3057\u304b\u4f7f\u3048\u305a\u6c4e\u7528\u6027\u304c\u4f4e\u3044\u306e\u3067\u3001<span style=\"color: #ff0000;\"><strong>\u6c4e\u7528\u6027\u3092\u8003\u616e\u3059\u308b\u3068CASE\u5f0f\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3044<\/strong><\/span>\u3068\u3082\u8a00\u308f\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u96c6\u7d04\u95a2\u6570(\u30c7\u30fc\u30bf\u306e\u96c6\u7d04\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u95a2\u6570)<\/h2>\n<h3>COUNT\u95a2\u6570<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\u6570\u3092\u6570\u3048\u308b\u3002<\/p>\n<h3>SUM\u95a2\u6570<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u306e\u6570\u5024\u5217\u306e\u30c7\u30fc\u30bf\u3092\u5408\u8a08\u3059\u308b\u3002<\/p>\n<h3>AVG\u95a2\u6570<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u306e\u6570\u5024\u5217\u306e\u30c7\u30fc\u30bf\u3092\u5e73\u5747\u3059\u308b\u3002<\/p>\n<h3>MAX\u95a2\u6570<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u306e\u4efb\u610f\u306e\u5217\u306e\u6700\u5927\u5024\u3092\u6c42\u3081\u308b\u3002<\/p>\n<h3>MIN\u95a2\u6570<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u306e\u4efb\u610f\u306e\u5217\u306e\u6700\u5c0f\u5024\u3092\u6c42\u3081\u308b\u3002<\/p>\n<h3>\u91cd\u8907\u5024\u3092\u9664\u5916\u3057\u3066\u96c6\u7d04\u95a2\u6570\u3092\u4f7f\u3046\u306b\u306f\uff1f<\/h3>\n<p>\u96c6\u7d04\u95a2\u6570\u3067\u306f\u3001\u96c6\u7d04\u95a2\u6570\u306e\u5f15\u6570\u306b<span style=\"color: #ff0000;\"><strong>\u300cDISTINCT\u30ad\u30fc\u30ef\u30fc\u30c9\u300d<\/strong><strong>\u3092\u4f7f\u7528<\/strong><\/span>\u3057\u3066\u3001\u91cd\u8907\u5024\u3092\u9664\u5916\u3057\u3066\u5b9f\u884c\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">SELECT COUNT(DISTINCT NAME) FROM ITEM;<\/pre>\n<p>\u305d\u306e\u969b\u306f\u3001\u5fc5\u305a\u30ab\u30c3\u30b3\u5185\u306b\u8a18\u8ff0\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u96c6\u7d04\u95a2\u6570\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u53e5\u306f\uff1f<\/h3>\n<p>\u96c6\u8a08\u95a2\u6570\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306f\u3001\u4e0b\u8a18\u306e\u4e09\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li>SELECT\u53e5<\/li>\n<li>HAVING\u53e5<\/li>\n<li>ORDER BY\u53e5<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"SQL\u306e\u95a2\u6570\u306f\u5927\u304d\u304f\u4e0b\u8a18\u306e\u7a2e\u985e\u306b\u5206\u304b\u308c\u307e\u3059\u3002 \u7b97\u8853\u95a2\u6570\uff08\u6570\u5024\u8a08\u7b97\u306e\u305f\u3081\u306e\u95a2\u6570\uff09 \u6587\u5b57\u5217\u95a2\u6570\uff08\u6587\u5b57\u5217\u64cd\u4f5c\u306e\u305f\u3081\u306e\u95a2\u6570\uff09 \u65e5\u4ed8\u95a2\u6570\uff08\u65e5\u4ed8\u64cd\u4f5c\u306e\u305f\u3081\u306e\u95a2\u6570\uff09 \u5909\u63db\u95a2\u6570\uff08\u30c7\u30fc\u30bf\u578b\u3084\u3001\u5024\u3092\u5909\u63db\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff09 \u96c6\u7d04\u95a2\u6570\uff08\u30c7\u30fc\u30bf\u96c6\u8a08 [&hellip;]","protected":false},"author":1,"featured_media":4823,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4723"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4723"}],"version-history":[{"count":19,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4723\/revisions"}],"predecessor-version":[{"id":20594,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4723\/revisions\/20594"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/4823"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4723"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}