{"id":5999,"date":"2017-09-28T07:56:52","date_gmt":"2017-09-27T22:56:52","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=5999"},"modified":"2017-09-28T07:56:52","modified_gmt":"2017-09-27T22:56:52","slug":"databaseoracleodbc","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/databaseoracleodbc\/","title":{"rendered":"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08Oracle\uff09\u306b\u63a5\u7d9a\u3059\u308b\uff08ODBC \u3092\u4f7f\u7528\uff09"},"content":{"rendered":"<h2>ODBC\u63a5\u7d9a\uff08ADO\uff09<\/h2>\n<div class=\"m30-l\">\n<p><strong>ADO<\/strong>\u3067\u3001<strong>ODBC\uff08Open Database Connectivity\uff09\u30c9\u30e9\u30a4\u30d0<\/strong>\u3092\u4f7f\u3063\u3066\u3001Oracle \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u63a5\u7d9a\u3059\u308b\u5834\u5408\u3001<strong>Open \u30e1\u30bd\u30c3\u30c9<\/strong> \u306e <strong>ConnectionString \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b\u3001<strong>ODBC\u30c9\u30e9\u30a4\u30d0\u540d<\/strong>\u3092\u6307\u5b9a\u3059\u308b\u63a5\u7d9a\u6587\u5b57\u5217\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<br \/>\n    \u3000\u3000\u2192\u3000<a href=\"https:\/\/excelwork.info\/excel\/databaseoracle\/\">OLE DB \u306b\u3088\u308b\u63a5\u7d9a<\/a><br \/>\n    \u3000\u3000\u2192\u3000<a href=\"https:\/\/excelwork.info\/excel\/commingsoon\/\">oo4o \u306b\u3088\u308b\u63a5\u7d9a<\/a><\/p>\n<h3>\u63a5\u7d9a\u6587\u5b57\u5217<\/h3>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010ConnectionString\uff08ADO\uff09\u306b\u8a2d\u5b9a\u3059\u308b\u6587\u5b57\u5217\u3011<\/strong><\/p>\n<p>    <span class=\"red\"><strong>\uff1c\u30c9\u30e9\u30a4\u30d0\u540d\u30fb\u30cd\u30c3\u30c8\u30b5\u30fc\u30d3\u30b9\u540d\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408\uff1e<\/strong><\/span><br \/>\n    <strong>DRIVER<\/strong> = <strong>{Microsoft ODBC for Oracle}<\/strong>;<br \/>\n    <strong>CONNECTSTRING<\/strong> = <em>NetServiceName<\/em>;<br \/>\n    <strong>UID<\/strong> = <em>UserName<\/em>;<br \/>\n    <strong>PWD<\/strong> = <em>PassWord<\/em>;<\/p>\n<p>    <span class=\"red\"><strong>\uff1c\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u540d\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408\uff1e<\/strong><\/span><br \/>\n    <strong>DSN<\/strong> = <em>DSN<\/em>;<strong>UID<\/strong> = <em>UserName<\/em>;<strong>PWD<\/strong> = <em>PassWord<\/em>;<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>NetServiceName&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;tnsnames.ora \u30d5\u30a1\u30a4\u30eb\u306e\u30cd\u30c3\u30c8\u30b5\u30fc\u30d3\u30b9\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>UserName&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>PassWord&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>DSN&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u540d\u3092\u3057\u3066\u3044\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<br \/><\/div>\n<\/div>\n<br \/><br \/>\n<h2>Oracle \u63a5\u7d9a\uff08ODBC\uff09<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Oracle\uff08ODBC\uff09\u3078\u63a5\u7d9a\u3059\u308b\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_ODBC_oracle()\r\n    \r\n    Dim oraCon As ADODB.Connection\r\n    Dim oraRs As ADODB.Recordset\r\n    Dim constr As String\r\n    Dim strSQL As String\r\n    Dim col As Long\r\n    Dim row As Long\r\n    \r\n    Const DRIVER = \"{Microsoft ODBC for Oracle}\"    '\u30c9\u30e9\u30a4\u30d0\u540d\uff08Microsoft\u793e\u88fd\uff09\r\n    'Const DRIVER = \"{Oracle in OraDb11g_home1}\"    '\u30c9\u30e9\u30a4\u30d0\u540d\uff08Oracle\u793e\u88fd\uff09\r\n    Const NETSERVICENAME = \"hpdb1\"                  'tnsnames.ora \u30d5\u30a1\u30a4\u30eb\u306e\u30cd\u30c3\u30c8\u30b5\u30fc\u30d3\u30b9\u540d'\r\n    Const DSN = \"ORACL_hpdb1\"                       '\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u540d\r\n    Const USERNAME = \"uhpdb1\"                       '\u63a5\u7d9a\u3059\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30e6\u30fc\u30b6\u30fc\u540d\r\n    Const PASSWORD = \"uhpdb1\"                       '\u30d1\u30b9\u30ef\u30fc\u30c9\r\n    \r\n    Set oraCon = New ADODB.Connection\r\n    \r\n    '\u30c9\u30e9\u30a4\u30d0\u30fc\u540d\u30fb\u30cd\u30c3\u30c8\u30b5\u30fc\u30d3\u30b9\u540d\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408\r\n    constr = \"DRIVER=\" & DRIVER\r\n    constr = constr & \";CONNECTSTRING=\" & NETSERVICENAME\r\n    constr = constr & \";UID=\" & USERNAME\r\n    constr = constr & \";PWD=\" & PASSWORD & \";\"\r\n    \r\n    '\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u540d\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408\r\n'    constr = \"DSN=\" & DSN\r\n'    constr = constr & \";UID=\" & USERNAME\r\n'    constr = constr & \";PWD=\" & PASSWORD\r\n    \r\n    oraCon.ConnectionString = constr\r\n    oraCon.Open\r\n    \r\n    strSQL = \"select * from table01 order by id desc\"\r\n    \r\n    Set oraRs = New ADODB.Recordset\r\n    oraRs.Open strSQL, oraCon\r\n    \r\n    With Worksheets(\"oracle_odbc\")\r\n    \r\n        .Cells.Clear\r\n    \r\n        '\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\r\n        For col = 0 To oraRs.Fields.Count - 1\r\n            .Cells(1, col + 1) = oraRs(col).Name\r\n        Next col\r\n    \r\n        '\u30ec\u30b3\u30fc\u30c9\r\n        Do Until oraRs.EOF\r\n            For col = 0 To oraRs.Fields.Count - 1\r\n                .Cells(row + 2, col + 1) = oraRs(col).Value\r\n            Next col\r\n            row = row + 1\r\n            oraRs.MoveNext\r\n        Loop\r\n    \r\n    End With\r\n    \r\n    oraRs.Close\r\n    oraCon.Close\r\n    Set oraCon = Nothing\r\n    \r\nEnd Sub\r\n    \r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><a href=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracleodbc_01.jpg?ssl=1\" rel=\"lightbox[5999]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracleodbc_01.jpg?resize=390%2C243&#038;ssl=1\" alt=\"SQL\u5b9f\u884c\u7d50\u679c\" width=\"390\" height=\"243\" class=\"alignnone size-full wp-image-6003\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>ODBC\u63a5\u7d9a\uff08ADO\uff09 ADO\u3067\u3001ODBC\uff08Open Database Conn &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6003,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[953,950,954,958,957,959,956,952,951,960,814,955,949],"jetpack_featured_media_url":"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracleodbc_01.jpg?fit=390%2C243&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1yL","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5999"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=5999"}],"version-history":[{"count":10,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5999\/revisions"}],"predecessor-version":[{"id":6448,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5999\/revisions\/6448"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6003"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=5999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=5999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=5999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}