{"id":5959,"date":"2017-09-27T09:07:49","date_gmt":"2017-09-27T00:07:49","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=5959"},"modified":"2017-09-28T07:59:41","modified_gmt":"2017-09-27T22:59:41","slug":"databaseoracle","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/databaseoracle\/","title":{"rendered":"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08Oracle\uff09\u306b\u63a5\u7d9a\u3059\u308b\uff08OLE DB \u3092\u4f7f\u7528\uff09"},"content":{"rendered":"<h2>OLE DB \u30d7\u30ed\u30d0\u30a4\u30c0<\/h2>\n<div class=\"m30-l\">\n<p><strong>OLE DB<\/strong>\u306b\u306f\u3001Oracle \u63d0\u4f9b\u306e <strong>Oracle Provider for OLE DB<\/strong> \u3068 Microsoft \u63d0\u4f9b\u306e <strong>OLE DB Provider for Oracle<\/strong> \u306e\uff12\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002\u3044\u305a\u308c\u306e\u5834\u5408\u3082 ADO \u3092\u4f7f\u7528\u3057\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n    \u307e\u305f\u3001<strong>OLE DB<\/strong> \u306e\u4ed6\u306b\u3001<a href=\"https:\/\/excelwork.info\/excel\/databaseoracleodbc\/\">ODBC<\/a> \u3084 <a href=\"https:\/\/excelwork.info\/excel\/commingsoon\/\">oo4o<\/a> \u3068\u3044\u3063\u305f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<\/div>\n<br \/>\n<h2>Oracle Provider for OLE DB<\/h2>\n<div class=\"m30-l\">\n<p>Oracle \u306b\u63a5\u7d9a\u3059\u308b\u306b\u306f\u3001<strong>Oracle Client<\/strong> \u304c\u5fc5\u8981\u3067\u3059\u3002<br \/>\n    <strong>ADO<\/strong> \u3067\u63a5\u7d9a\u3059\u308b\u306b\u306f <strong>Open \u30e1\u30bd\u30c3\u30c9<\/strong>\u306e <strong>ConnectionString \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong> \u306b\u3001<strong>OraOLEDB.Oracle<\/strong> \u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<h3>\u63a5\u7d9a\u6587\u5b57\u5217\u30d1\u30e9\u30e1\u30fc\u30bf<\/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>\uff1ctnsnames.ora \u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\uff1e<\/strong><\/span><br \/>\n    <strong>Provider<\/strong> = <strong>OraOLEDB.Oracle<\/strong>;<br \/>\n    <strong>Data Source<\/strong> = <em>ServerName<\/em>;<br \/>\n    <strong>User ID<\/strong> = <em>UserName<\/em>;<br \/>\n    <strong>Password<\/strong> = <em>UserPassword<\/em>;<\/p>\n<p>    <span class=\"red\"><strong>\uff1ctnsnames.ora \u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u305b\u305a\u76f4\u63a5\u6307\u5b9a\u3059\u308b\u5834\u5408\uff1e<\/strong><\/span><br \/>\n    <strong>Provider<\/strong> = <strong>OraOLEDB.Oracle<\/strong>;<br \/>\n    <strong>Data Source<\/strong> = <em>StrDataSource<\/em>;<br \/>\n    <strong>User ID<\/strong> = <em>UserName<\/em>;<br \/>\n    <strong>Password<\/strong> = <em>UserPassword<\/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>ServerName&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>UserPassword&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>StrDataSource&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;tnsnames.ora \u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u305d\u306e\u307e\u307e\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/li>\n<p>      <br \/>\uff1ctnsnames.ora \u30d5\u30a1\u30a4\u30eb\uff1e<br \/>\n      <a href=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracle_01e.jpg?ssl=1\" rel=\"lightbox[5959]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracle_01e.jpg?resize=550%2C195&#038;ssl=1\" alt=\"ora \u30d5\u30a1\u30a4\u30eb\" width=\"550\" height=\"195\" class=\"alignnone size-full wp-image-5977\" srcset=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracle_01e.jpg?w=550&amp;ssl=1 550w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracle_01e.jpg?resize=400%2C142&amp;ssl=1 400w\" sizes=\"(max-width: 550px) 100vw, 550px\" data-recalc-dims=\"1\" \/><\/a>\n    <\/ul>\n<\/p><\/div>\n<p class=\"caution4\"><strong>ADO<\/strong> \u306b\u95a2\u3057\u3066\u306f <a href=\"https:\/\/excelwork.info\/excel\/databaseadobase\/\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08Access \u7b49\uff09\u306b\u63a5\u7d9a\uff08ADO\uff09<\/a> \u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<\/div>\n<br \/><br \/>\n<h2>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08Oracle\uff09\u3078\u63a5\u7d9a\u3059\u308b\u4f8b\uff08Oracle OLE DB \u3092\u4f7f\u7528\uff09<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b91<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Oracle OLE DB \u3092\u4f7f\u7528\" data-url=\"http:\/\/example.co.jp\" >\r\n\r\nSub Sample_OLEDB_Oracle()\r\n\r\n    'tnsnames.ora \u30d5\u30a1\u30a4\u30eb\u306e\u30cd\u30c3\u30c8\u30b5\u30fc\u30d3\u30b9\u540d'\r\n    Const STRDATASOURCE = \"hpdb1\"\r\n    \r\n    'tnsnames.ora \u3092\u4f7f\u7528\u3057\u306a\u3044\u5834\u5408\uff08\u76f4\u63a5\u6307\u5b9a\uff09\r\n    'Const STRDATASOURCE = _\r\n    '    \"(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)\" & _\r\n    '    \"(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SID = hpdb1)))\"\r\n    \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    Dim oraCon As New ADODB.Connection\r\n    Dim oraCmd As New ADODB.Command\r\n    Dim constr As String\r\n    Dim strSQL As String\r\n\r\n    constr = \"Provider=OraOLEDB.Oracle\"\r\n    constr = constr & \";Data Source=\" & STRDATASOURCE\r\n    constr = constr & \";User ID=\" & USERNAME\r\n    constr = constr & \";Password=\" & PASSWORD\r\n    \r\n    oraCon.ConnectionString = constr\r\n    oraCon.Open\r\n    \r\n    strSQL = \"insert all \"\r\n    strSQL = strSQL & \"into table01 (id, name) \"\r\n    strSQL = strSQL & \"values (1, '\u5c71\u7530\u592a\u90ce') \"\r\n    strSQL = strSQL & \"into table01 (id, name) \"\r\n    strSQL = strSQL & \"values (2, '\u5c71\u672c\u82b1\u5b50') \"\r\n    strSQL = strSQL & \"into table01 (id, name) \"\r\n    strSQL = strSQL & \"values (3, '\u7530\u4e2d\u4e00\u90ce') \"\r\n    strSQL = strSQL & \"select * from dual\"\r\n\r\n    With oraCmd\r\n        .ActiveConnection = oraCon\r\n        .CommandText = strSQL\r\n        .Execute\r\n    End With\r\n\r\n    Set oraCmd = Nothing\r\n    oraCon.Close\r\n    Set oraCon = Nothing\r\n\r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<\/div>\n<br \/><br \/>\n<h2>Microsoft OLE DB Provider for ODBC<\/h2>\n<div class=\"m30-l\">\n<p>Oracle \u306b\u63a5\u7d9a\u3059\u308b\u306b\u306f\u3001<strong>Oracle Client<\/strong> \u304c\u5fc5\u8981\u3067\u3059\u3002<br \/>\n    <strong>ADO<\/strong> \u3067\u63a5\u7d9a\u3059\u308b\u306b\u306f <strong>Open \u30e1\u30bd\u30c3\u30c9<\/strong>\u306e <strong>ConnectionString \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong> \u306b\u3001<strong>MSDAORA<\/strong> \u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<h3>\u63a5\u7d9a\u6587\u5b57\u5217\u30d1\u30e9\u30e1\u30fc\u30bf<\/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>\uff1ctnsnames.ora \u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\uff1e<\/strong><\/span><br \/>\n    <strong>Provider<\/strong> = <strong>MSDAORA<\/strong>;<br \/>\n    <strong>Data Source<\/strong> = <em>ServerName<\/em>;<br \/>\n    <strong>User ID<\/strong> = <em>UserName<\/em>;<br \/>\n    <strong>Password<\/strong> = <em>UserPassword<\/em>;<\/p>\n<p>    <span class=\"red\"><strong>\uff1ctnsnames.ora \u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u305b\u305a\u76f4\u63a5\u6307\u5b9a\u3059\u308b\u5834\u5408\uff1e<\/strong><\/span><br \/>\n    <strong>Provider<\/strong> = <strong>MSDAORA<\/strong>;<br \/>\n    <strong>Data Source<\/strong> = <em>StrDataSource<\/em>;<br \/>\n    <strong>User ID<\/strong> = <em>UserName<\/em>;<br \/>\n    <strong>Password<\/strong> = <em>UserPassword<\/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>ServerName&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>UserPassword&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>StrDataSource&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;tnsnames.ora \u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u305d\u306e\u307e\u307e\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<\/div>\n<br \/><br \/>\n<h2>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08Oracle\uff09\u3078\u63a5\u7d9a\u3059\u308b\u4f8b\uff08Microsoft OLE DB \u3092\u4f7f\u7528\uff09<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9 2<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Microsoft OLE DB \u3092\u4f7f\u7528\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_OLEDB_Microsoft()\r\n\r\n    'tnsnames.ora \u30d5\u30a1\u30a4\u30eb\u306e\u30cd\u30c3\u30c8\u30b5\u30fc\u30d3\u30b9\u540d'\r\n    'Const STRDATASOURCE = \"hpdb1\"\r\n    \r\n    'tnsnames.ora \u3092\u4f7f\u7528\u3057\u306a\u3044\u5834\u5408\uff08\u76f4\u63a5\u6307\u5b9a\uff09\r\n    Const STRDATASOURCE = _\r\n        \"(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)\" & _\r\n        \"(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SID = hpdb1)))\"\r\n    \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    Dim oraCon As new ADODB.Connection\r\n    Dim oraRs As new ADODB.Recordset\r\n    Dim constr As String\r\n    Dim strSQL As String\r\n\r\n    constr = \"Provider=MSDAORA\"\r\n    constr = constr & \";Data Source=\" & STRDATASOURCE\r\n    constr = constr & \";User ID=\" & USERNAME\r\n    constr = constr & \";Password=\" & PASSWORD\r\n    \r\n    oraCon.ConnectionString = constr\r\n    oraCon.Open\r\n    \r\n    strSQL = \"select * from table01\"\r\n\r\n    oraRs.Open strSQL, oraCon\r\n    \r\n    With Worksheets(\"oracle\")\r\n        .Cells.Clear\r\n        .Range(\"A1\").CopyFromRecordset oraRs\r\n    End With\r\n    \r\n    oraRs.Close\r\n    oraCon.Close\r\n    Set oraRs = Nothing\r\n    Set oraCon = Nothing\r\n\r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p>  <a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracle_02.jpg?ssl=1\" rel=\"lightbox[5959]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/databaseoracle_02.jpg?resize=393%2C248&#038;ssl=1\" alt=\"oracle \u63a5\u7d9a\u7d50\u679c\" width=\"393\" height=\"248\" class=\"alignnone size-full wp-image-5985\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>OLE DB \u30d7\u30ed\u30d0\u30a4\u30c0 OLE DB\u306b\u306f\u3001Oracle \u63d0\u4f9b\u306e Oracle  &#8230; <\/p>\n","protected":false},"author":1,"featured_media":5977,"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\/databaseoracle_01e.jpg?fit=550%2C195&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1y7","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5959"}],"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=5959"}],"version-history":[{"count":43,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5959\/revisions"}],"predecessor-version":[{"id":6450,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/5959\/revisions\/6450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/5977"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=5959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=5959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=5959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}