{"id":1026,"date":"2020-04-03T00:00:00","date_gmt":"2020-04-02T15:00:00","guid":{"rendered":"https:\/\/www.ishikawasekkei.com\/?p=1026"},"modified":"2020-05-02T14:57:15","modified_gmt":"2020-05-02T05:57:15","slug":"pl-sql-short-insert-statement-cursor-for-loop","status":"publish","type":"post","link":"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/04\/03\/pl-sql-short-insert-statement-cursor-for-loop\/","title":{"rendered":"PL\/SQL \u52b9\u7387\u306e\u826f\u3044\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0"},"content":{"rendered":"\n<p>\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u4eca\u65e5\u306f\u3001\u304a\u4ed5\u4e8b\u3067\u30aa\u30e9\u30af\u30eb\u306ePL\/SQL\u306e\u30b9\u30c8\u30a2\u30c9\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3092\u4f5c\u3063\u3066\u3044\u3066\u3001\u53c2\u8003\u306b\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u66f8\u304d\u65b9\u304c\u6c17\u306b\u5165\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u305d\u306e\u3053\u3068\u3092\u8a18\u4e8b\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u3069\u3053\u304c\u6c17\u306b\u5165\u3089\u306a\u304b\u3063\u305f\u3063\u3066\u3001\u5927\u304d\u304f\u306f\u30012\u70b9\u3067\u3059\u3002\u30ab\u30fc\u30bd\u30eb\u3092\u4f7f\u3063\u305f\u30eb\u30fc\u30d7\u306e\u66f8\u304d\u65b9\u3068\u3001%ROWTYPE\u3092\u4f7f\u3063\u305fINSERT\u6587\u306e\u66f8\u304d\u65b9\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30ab\u30fc\u30bd\u30ebFOR\u30eb\u30fc\u30d7<\/h2>\n\n\n\n<p>\u3000PL\/SQL\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089SELECT\u6587\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u3063\u3066\u304d\u3066\u4e00\u4ef6\u305a\u3064\u51e6\u7406\u3092\u3059\u308b\u3001\u3068\u3044\u3046\u3053\u3068\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002SELECT\u6587\u3092\u4f7f\u3046\u3068\u304d\u306f\u3001\u660e\u793a\u7684\u306b\u304b\u6697\u9ed9\u7684\u306b\u304b\u3044\u305a\u308c\u306b\u305b\u3088\u3001\u30ab\u30fc\u30bd\u30eb\u3068\u3044\u3046\u3082\u306e\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002\u30ab\u30fc\u30bd\u30eb\u306f\u3001\u554f\u3044\u5408\u308f\u305b\u7d50\u679c\u306e\u4f4d\u7f6e\u3092\u793a\u3059\u30dd\u30a4\u30f3\u30bf\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002\u6697\u9ed9\u7684\u306a\u30ab\u30fc\u30bd\u30eb\u306fPL\/SQL\u3067\u306f\u4e00\u884c\u306e\u307f\u7d50\u679c\u3092\u623b\u3059SELECT\u6587\u3084\u3001UPDATE\u6587\u3001DELETE\u6587\u306a\u3069\u3067\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u3002\u8907\u6570\u884c\u623b\u3059SELECT\u6587\u3092\u5229\u7528\u3059\u308b\u3068\u304d\u306b\u306f\u3001\u5fc5\u305a\u660e\u793a\u7684\u306b\u30ab\u30fc\u30bd\u30eb\u3092\u5b9a\u7fa9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u3001\u30ab\u30fc\u30bd\u30eb\u3092OPEN\u3057\u3066\u3001FETCH\u3057\u3066\u3001FETCH\u304c\u7d42\u308f\u3063\u305f\u3089\u3001CLOSE\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- \u30ab\u30fc\u30bd\u30eb\u5b9a\u7fa9\nCURSOR c IS SELECT ...;\n\n-- \u51e6\u7406\u90e8\u5206\nOPEN c;\nLOOP\n  -- FETCH\n  FETCH c INTO \u5909\u65701, \u5909\u65702, ...;\n  -- \u7d42\u4e86\u6761\u4ef6\n  EXIT WHEN c%NOTFOUND;\n  -- 1\u4ef6\u3054\u3068\u306e\u51e6\u7406\u3092\u3053\u3053\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002\nEND LOOP;\nCLOSE c;<\/pre>\n\n\n\n<p>\u3000\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002\u81ea\u5206\u3067\u30ab\u30fc\u30bd\u30eb\u3092OPEN\u3057\u3066\u3001\u7d42\u308f\u3063\u305f\u3089CLOSE\u3059\u308b\u3001\u3068\u3044\u3046\u306e\u304c\u30bb\u30aa\u30ea\u30fc\u3067\u3059\u3002\u3053\u306e\u5834\u5408\u3001\u500b\u5225\u306e\u7d42\u4e86\u6761\u4ef6\u3092\u6e80\u305f\u3059\u5834\u5408\u3084\u3001\u4f8b\u5916\u306a\u3069\u306e\u7570\u5e38\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u306b\u3082CLOSE\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002OPEN\u3001CLOSE\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3046\u308f\u305a\u3089\u308f\u3057\u3055\u304b\u3089\u89e3\u653e\u3057\u3066\u304f\u308c\u308b\u8a18\u6cd5\u3068\u3057\u3066\u3001\u30ab\u30fc\u30bd\u30ebFOR\u30eb\u30fc\u30d7\u3068\u3044\u3046\u66f8\u304d\u65b9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- \u30ab\u30fc\u30bd\u30eb\u5b9a\u7fa9\nCURSOR c IS SELECT ...;\n\n-- \u51e6\u7406\u90e8\u5206\nFOR i IN c LOOP\n  -- 1\u4ef6\u3054\u3068\u306e\u51e6\u7406\u3092\u3053\u3053\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002\n  -- \u9805\u76ee\u306e\u30c7\u30fc\u30bf\u306f\u3001\u300ci.\u30ab\u30e9\u30e0\u540d\u300d\u3068\u3044\u3046\u98a8\u306b\u8a18\u8f09\u3067\u304d\u307e\u3059\u3002\nEND LOOP;<\/pre>\n\n\n\n<p>\u3000\u3053\u306e\u8a18\u6cd5\u3001OPEN\u3001FETCH\u3001CLOSE\u3001\u7d42\u4e86\u6761\u4ef6\u3092\u8a18\u8f09\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u305b\u3093\u3002\u3042\u3001\u3042\u3068\u3001\u53d6\u5f97\u3057\u3066\u304d\u305f\u30c7\u30fc\u30bf\u3092\u5909\u6570\u306b\u4ee3\u5165\u3059\u308b\u51e6\u7406\u3082\u3001\u305d\u306e\u5909\u6570\u306e\u5b9a\u7fa9\u3082\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u305b\u3093\u3002\u3068\u3063\u3066\u3082\u30a8\u30ec\u30ac\u30f3\u30c8\u3067\u3059\u306d\u3002\u7279\u306b\u7406\u7531\u304c\u306a\u3044\u9650\u308a\u3001\u30ab\u30fc\u30bd\u30ebFOR\u30eb\u30fc\u30d7\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002\u307c\u304f\u306f\u30011\u4ef6\u3060\u3051\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308bSQL\u304c\u4f55\u5ea6\u3082\u547c\u3070\u308c\u308b\u3068\u304d\u306b\u3060\u3051\u3001OPEN\u3001FETCH\u3001CLOSE\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u901a\u5e38\u306eSELECT\u6587\u306f\u3001\u30c7\u30fc\u30bf\u304c1\u4ef6\u3057\u304b\u306a\u304f\u3066\u30822\u4ef6\u76ee\u3092\u63a2\u3057\u306b\u884c\u3063\u3066\u3001\u898b\u3064\u304b\u3089\u306a\u3044\u3053\u3068\u304c\u308f\u304b\u3063\u3066\u521d\u3081\u3066\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3067\u304d\u308b\u306e\u3067\u3001\u82e5\u5e72\u3067\u3059\u304c\u3001\u51e6\u7406\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u6697\u9ed9\u30ab\u30fc\u30bd\u30eb\u306eSELECT\u306e\u5834\u5408\u3082TOO_MANY_ROWS\u4f8b\u5916\u3092\u767a\u751f\u3055\u305b\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b2\u4ef6\u76ee\u304c\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002\u901a\u5e38\u306f\u51e6\u7406\u6642\u9593\u306f\u308f\u305a\u304b\u3067\u3059\u306e\u3067\u3001\u307b\u3068\u3093\u3069\u6c17\u306b\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305f\u3060\u3001\u5927\u91cf\u30c7\u30fc\u30bf\u3092\u6271\u3046\u5834\u5408\u306a\u3069\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u6c17\u306b\u306a\u308b\u3068\u304d\u306b\u306f\u8003\u616e\u3057\u3066\u3082\u3088\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u306d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\uff05ROWTYPE\u3092\u5229\u7528\u3057\u305fINSERT\u6587<\/h2>\n\n\n\n<p>\u3000\u30aa\u30e9\u30af\u30eb\u306b\u306f\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3092\u518d\u5229\u7528\u3059\u308b\u305f\u3081\u306e\u8a18\u6cd5\u3068\u3057\u3066\u3001%ROWTYPE\u3068\u3044\u3046\u8a18\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002\u5ba3\u8a00\u90e8\u5206\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002\u3053\u308c\u3060\u3051\u3067\u3001myRecord\u3068\u3044\u3046\u5909\u6570\u306e\u4e2d\u306b\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3068\u540c\u3058\u9805\u76ee\u3092\u5ba3\u8a00\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">myRecord myTable%ROWTYPE; -- myTable\u30c6\u30fc\u30d6\u30eb\u306e\u9805\u76ee\u3068\u540c\u3058\u9805\u76ee\u3092\u6301\u3064\u5909\u6570\u3092\u5b9a\u7fa9<\/pre>\n\n\n\n<p>\u3000\u3053\u306emyRecord\u5909\u6570\u3092\u5229\u7528\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bINSERT\u6587\u3092\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">INSERT INTO myTable VALUES myRecord;<\/pre>\n\n\n\n<p>\u3000\u3053\u306e\u8a18\u8ff0\u65b9\u6cd5\u3092\u77e5\u3089\u306a\u3044\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u9805\u76ee\u306e\u6570\u306e2\u500d\u306e\u8a18\u8ff0\u304c\u5fc5\u8981\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">INSERT INTO myTable(\n  COLUMN_NAME1,\n  COLUMN_NAME2,\n\u2026\n  COLUMN_NAMEn\n)VALUES(\n  myRecord.COLUMN_NAME1,\n  myRecord.COLUMN_NAME2,\n...\n  myRecord.COLUMN_NAMEn\n);<\/pre>\n\n\n\n<p>\u3000\u3061\u306a\u307f\u306b\u3001\u3053\u306emyRecord\u306e\u521d\u671f\u5316\u306f\u5909\u6570\u306bNULL\u3092\u4ee3\u5165\u3059\u308b\u3060\u3051\u3067\u5b8c\u4e86\u3067\u3059\u3002\u3059\u3079\u3066\u306e\u9805\u76ee\u304cNULL\u306b\u30bb\u30c3\u30c8\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">myRecord := NULL;<\/pre>\n\n\n\n<p>\u3000\u30c6\u30fc\u30d6\u30eb\u3078\u30c7\u30fc\u30bf\u3092INSERT\u3059\u308b\u3068\u304d\u306f\u3001%ROWTYPE\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002%ROWTYPE\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u9805\u76ee\u306e\u5897\u6e1b\u304c\u3042\u3063\u3066\u3082\u65e2\u5b58\u90e8\u5206\u306f\u307b\u307c\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3057\u307e\u3059\u3002%ROWTYPE\u3092\u4f7f\u308f\u306a\u3051\u308c\u3070\u3001\u3059\u3079\u3066\u306e\u9805\u76ee\u3092\u518d\u5b9a\u7fa9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u3001\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306e\u52b9\u7387\u304c\u305a\u3044\u3076\u3093\u3068\u60aa\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u3000PL\/SQL\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3092\u3059\u308b\u3068\u304d\u306f\u3001\u30ab\u30fc\u30bd\u30ebFOR\u30eb\u30fc\u30d7\u3092\u4f7f\u3046\u3001\u30c6\u30fc\u30d6\u30eb\u3078\u30c7\u30fc\u30bf\u3092INSERT\u3059\u308b\u3068\u304d\u306f\u3001%ROWTYPE\u3067\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3092\u53c2\u7167\u3057\u305f\u5909\u6570\u3092\u5229\u7528\u3059\u308b\u3002\u3053\u308c\u3060\u3051\u3067\u3001\u305a\u3044\u3076\u3093\u3068\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306e\u6642\u9593\u304c\u77ed\u7e2e\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002 \u3000\u4eca\u65e5\u306f\u3001\u304a\u4ed5\u4e8b\u3067\u30aa\u30e9\u30af\u30eb\u306ePL\/SQL\u306e\u30b9\u30c8\u30a2\u30c9\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3092\u4f5c\u3063\u3066\u3044\u3066\u3001\u53c2\u8003\u306b\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u66f8\u304d\u65b9\u304c\u6c17\u306b\u5165\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u305d\u306e\u3053\u3068\u3092\u8a18\u4e8b\u306b\u3057 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/04\/03\/pl-sql-short-insert-statement-cursor-for-loop\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;PL\/SQL \u52b9\u7387\u306e\u826f\u3044\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2],"tags":[],"class_list":["post-1026","post","type-post","status-publish","format-standard","hentry","category-program","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/comments?post=1026"}],"version-history":[{"count":7,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1026\/revisions"}],"predecessor-version":[{"id":1225,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1026\/revisions\/1225"}],"wp:attachment":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/media?parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/categories?post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/tags?post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}