{"id":1631,"date":"2020-06-09T22:40:29","date_gmt":"2020-06-09T13:40:29","guid":{"rendered":"https:\/\/obenkyolab.com\/?p=1631"},"modified":"2021-06-05T23:52:28","modified_gmt":"2021-06-05T14:52:28","slug":"python%e3%81%8b%e3%82%89oracle%e3%81%b8%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e4%b8%80%e6%8b%ac%e6%8c%bf%e5%85%a5","status":"publish","type":"post","link":"https:\/\/obenkyolab.com\/?p=1631","title":{"rendered":"\u3010Python\u3011cx_Oracle\u3067\u30c7\u30fc\u30bf\u3092\u4e00\u62ec\u633f\u5165\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><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><\/span><\/a><\/span><\/div>\n<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:\/\/obenkyolab.com\/?p=1631\/#%E6%A6%82%E8%A6%81\" >\u6982\u8981<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/obenkyolab.com\/?p=1631\/#%E7%92%B0%E5%A2%83\" >\u74b0\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/obenkyolab.com\/?p=1631\/#Step1_Oracle%E5%81%B4%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E4%BD%9C%E6%88%90\" >Step1 : Oracle\u5074\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/obenkyolab.com\/?p=1631\/#Step2_Python%E3%81%AB%E3%82%88%E3%82%8B%E4%B8%80%E6%8B%AC%E6%8C%BF%E5%85%A5%E3%82%B3%E3%83%BC%E3%83%89\" >Step2 : Python\u306b\u3088\u308b\u4e00\u62ec\u633f\u5165\u30b3\u30fc\u30c9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/obenkyolab.com\/?p=1631\/#%E3%81%BE%E3%81%A8%E3%82%81\" >\u307e\u3068\u3081<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A6%82%E8%A6%81\"><\/span>\u6982\u8981<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>python\u304b\u3089Oracle\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u64cd\u4f5c\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066cx_Oracle\u304c\u3042\u308a\u307e\u3059\u3002cx_Oracle\u3092\u4f7f\u3063\u3066Oracle\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u30ec\u30b3\u30fc\u30c9\u3092\u633f\u5165\u3059\u308b\u3053\u3068\u306f\u3082\u3061\u308d\u3093\u53ef\u80fd\u3067\u3059\u304c\u3001<span class=\"su-highlight\" style=\"background:#f4fe2c;color:#000000\">&nbsp;<strong>\u5927\u91cf\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u633f\u5165\u3057\u305f\u3044\u5834\u5408<\/strong>&nbsp;<\/span>\u306f1\u30ec\u30b3\u30fc\u30c9\u305a\u3064\u3060\u3068\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u4eca\u56de\u306f\u3053\u308c\u3092\u5c11\u3057\u3067\u3082\u77ed\u3044\u6642\u9593\u3067\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306b\u3001<span class=\"su-highlight\" style=\"background:#f4fe2c;color:#000000\">&nbsp;<strong>\u4e00\u62ec\u3067\u633f\u5165\u3059\u308b<\/strong>&nbsp;<\/span>\u65b9\u6cd5\u306b\u3064\u3044\u3066\u5b9f\u8df5\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%92%B0%E5%A2%83\"><\/span>\u74b0\u5883<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>python  3.7.3<br>Oracle 18c Express Edition<\/p>\n\n\n\n<p>\u7121\u6599\u3067\u4f7f\u7528\u3067\u304d\u308bOracle Express Edition\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5\u306b\u3064\u3044\u3066\u306f\u3053\u3061\u3089\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-it-learning\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"FGcTGKdTxn\"><a href=\"https:\/\/obenkyolab.com\/?p=947\">Oracle Database Express Edition\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304b\u3089SQL\u767a\u884c\u307e\u3067<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Oracle Database Express Edition\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304b\u3089SQL\u767a\u884c\u307e\u3067&#8221; &#8212; Obenkyolab\" src=\"https:\/\/obenkyolab.com\/?p=947&#038;embed=true#?secret=jtXCpDPsqH#?secret=FGcTGKdTxn\" data-secret=\"FGcTGKdTxn\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step1_Oracle%E5%81%B4%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E4%BD%9C%E6%88%90\"><\/span>Step1 : Oracle\u5074\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u307e\u305a\u306fOracle\u5074\u306b\u30c6\u30b9\u30c8\u7528\u306e\u3068\u3057\u3066\u3001USER01\u3068\u3044\u3046\u30b9\u30ad\u30fc\u30de\u3092\u5b9a\u7fa9\u3057\u3001\u305d\u306e\u4e0b\u306boracle_insert\u3068\u3044\u3046\u540d\u524d\u306e\u30c6\u30fc\u30d6\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>SQL\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nCREATE TABLE USER01.ORACLE_INSERT(\n\tcol1 int\n\t,col2 int\n\t,col3 int\n)\n<\/pre><\/div>\n\n\n<p><br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step2_Python%E3%81%AB%E3%82%88%E3%82%8B%E4%B8%80%E6%8B%AC%E6%8C%BF%E5%85%A5%E3%82%B3%E3%83%BC%E3%83%89\"><\/span>Step2 : Python\u306b\u3088\u308b\u4e00\u62ec\u633f\u5165\u30b3\u30fc\u30c9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u7d9a\u3044\u3066Python\u304b\u3089\u5148\u307b\u3069\u4f5c\u6210\u3057\u305fOracle\u306e\u30c6\u30fc\u30d6\u30eb\u3078\u30c7\u30fc\u30bf\u3092\u633f\u5165\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002\u6d41\u308c\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>dataset\u3067\u633f\u5165\u3059\u308b\u30c7\u30fc\u30bf\u3092\u4f5c\u6210<\/li><li>cx_Oracle\u3067\u63a5\u7d9a\u3092\u4f5c\u6210<\/li><li><span class=\"su-highlight\" style=\"background:#f4fe2c;color:#000000\">&nbsp;<strong>cur.executemany()\u3067<\/strong>&nbsp;<\/span>\u5f15\u6570\u306bsql\u3068dataset\u3092\u5165\u308c\u3001<span class=\"su-highlight\" style=\"background:#f4fe2c;color:#000000\">&nbsp;<strong>\u4e00\u62ec\u3067\u633f\u5165<\/strong>&nbsp;<\/span><\/li><li>commit\u3068connection.close\u3057\u3066\u7d42\u4e86<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; highlight: [31]; title: ; notranslate\" title=\"\">\n#cx_Oracle\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8aad\u307f\u8fbc\u307f\nimport cx_Oracle\n\n#\u30ea\u30b9\u30c8\u578b\u3067\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5b9a\u7fa9\ndataset =&#x5B;\n    &#x5B;1,2,3]\n    ,&#x5B;4,5,6]\n    ,&#x5B;7,8,9]\n    ,&#x5B;10,11,12]\n    ,&#x5B;13,14,15]\n    ,&#x5B;16,17,18]\n    ,&#x5B;19,20,21]\n] \n\n#Oracle\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u60c5\u5831\u306e\u5b9a\u7fa9\nHOST = &#039;localhost&#039;\nPORT = &#039;1521&#039;\nDB_NAME = &#039;xepd1&#039;\nUSER = &#039;user01&#039;\nPASSWORD = &#039;password01&#039;\nSERVICE_NAME = &#039;xepdb1&#039;\n\n#\u63a5\u7d9a\u306e\u4f5c\u6210 \ntns = cx_Oracle.makedsn(HOST, PORT, service_name =SERVICE_NAME)\nconn = cx_Oracle.connect(USER,PASSWORD,tns)\n\n#\u30ab\u30fc\u30bd\u30eb\u306e\u53d6\u5f97\ncur = conn.cursor()\n\n#\u4e00\u62ec\u633f\u5165\ncur.executemany(&quot;insert into user01.oracle_insert (col1, col2, col3) values (:1, :2 ,:3)&quot;, dataset)\n\n#\u30b3\u30df\u30c3\u30c8\nconn.commit()\n\n#\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u5207\u65ad\nconn.close()\n<\/pre><\/div>\n\n\n<p>\u4e00\u62ec\u633f\u5165\u3059\u308b\u305f\u3081\u306e\u4ed5\u639b\u3051\u3068\u3057\u3066\u306fexecutemany()\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u90e8\u5206\u3067\u3059\u3002\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u4e00\u884c\u3065\u3064\u306e\u30ec\u30b3\u30fc\u30c9\u633f\u5165\u3067\u306f\u306a\u304f\u4e00\u62ec\u3067\u633f\u5165\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E3%81%BE%E3%81%A8%E3%82%81\"><\/span>\u307e\u3068\u3081<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e00\u62ec\u633f\u5165\u306e\u30b3\u30fc\u30c9\u81ea\u4f53\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u66f8\u3051\u307e\u3057\u305f\u3002\u305f\u3060\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u3064\u3044\u3066\u306f\u691c\u8a3c\u3067\u304d\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u4eca\u5f8c\u6642\u9593\u306a\u3069\u6e2c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4ee5\u4e0a<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Python\u3092\u4e00\u304b\u3089\u5b66\u3076\u306e\u306b\u304a\u3059\u3059\u3081\u306e\u672c\u306f\u30b3\u30c1\u30e9<\/span><\/strong><\/p>\n\n\n\n<iframe style=\"width:120px;height:240px;\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"https:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?ref=qf_sp_asin_til&#038;t=sebone0f-22&#038;m=amazon&#038;o=9&#038;p=8&#038;l=as1&#038;IS2=1&#038;detail=1&#038;asins=4873117380&#038;linkId=665846163826975f4858844e1483e9e7&#038;bc1=000000&amp;lt1=_blank&#038;fc1=333333&#038;lc1=0066c0&#038;bg1=ffffff&#038;f=ifr\">\n    <\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 python\u304b\u3089Oracle\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u64cd\u4f5c\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3068&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/obenkyolab.com\/?p=1631","footnotes":""},"categories":[13,7],"tags":[34,42],"class_list":["post-1631","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oracle","category-python","tag-sql","tag-42","ja"],"_links":{"self":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/1631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1631"}],"version-history":[{"count":10,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/1631\/revisions"}],"predecessor-version":[{"id":2906,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/1631\/revisions\/2906"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/media\/1218"}],"wp:attachment":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}