{"id":930277,"date":"2024-12-26T17:12:33","date_gmt":"2024-12-26T09:12:33","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930277.html"},"modified":"2024-12-26T17:12:35","modified_gmt":"2024-12-26T09:12:35","slug":"python%e5%a6%82%e4%bd%95%e8%bf%9eoracle","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930277.html","title":{"rendered":"python\u5982\u4f55\u8fdeoracle"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065105\/7023f9fd-8d20-4eac-998e-5f9566733624.webp\" alt=\"python\u5982\u4f55\u8fdeoracle\" \/><\/p>\n<p><p> <strong>Python\u8fde\u63a5Oracle\u6570\u636e\u5e93\u53ef\u4ee5\u901a\u8fc7cx_Oracle\u5e93\u5b9e\u73b0\u3001\u9700\u8981\u5b89\u88c5Oracle\u5ba2\u6237\u7aef\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528cx_Oracle\u5e93\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86Python\u4e0eOracle\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u63a5\u53e3\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5b89\u88c5\u4e86Oracle\u5ba2\u6237\u7aef\u8f6f\u4ef6\uff0c\u56e0\u4e3acx_Oracle\u9700\u8981\u4f9d\u8d56Oracle\u5ba2\u6237\u7aef\u5e93\u6765\u5b9e\u73b0\u5e95\u5c42\u7684\u6570\u636e\u5e93\u8fde\u63a5\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u914d\u7f6e\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\uff0c\u4ee5\u4fbfPython\u7a0b\u5e8f\u80fd\u591f\u6b63\u786e\u5730\u8bbf\u95eeOracle\u5ba2\u6237\u7aef\u5e93\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u8fde\u63a5Oracle\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5cx_Oracle\u5e93<\/p>\n<\/p>\n<p><p>\u8981\u5728Python\u4e2d\u8fde\u63a5Oracle\u6570\u636e\u5e93\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5cx_Oracle\u5e93\u3002cx_Oracle\u662f\u4e00\u4e2aPython\u6269\u5c55\u6a21\u5757\uff0c\u5141\u8bb8\u8bbf\u95eeOracle\u6570\u636e\u5e93\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7Python\u7684\u5305\u7ba1\u7406\u5de5\u5177pip\u6765\u5b89\u88c5\u8fd9\u4e2a\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install cx_Oracle<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u7b80\u5355\u6d4b\u8bd5cx_Oracle\u5e93\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cx_Oracle<\/p>\n<p>try:<\/p>\n<p>    print(&quot;cx_Oracle version:&quot;, cx_Oracle.__version__)<\/p>\n<p>    print(&quot;Installation successful!&quot;)<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(&quot;Error:&quot;, e)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u5b89\u88c5Oracle\u5ba2\u6237\u7aef<\/p>\n<\/p>\n<p><p>cx_Oracle\u9700\u8981Oracle\u5ba2\u6237\u7aef\u5e93\u7684\u652f\u6301\u3002Oracle\u63d0\u4f9b\u4e86\u51e0\u4e2a\u4e0d\u540c\u7684\u5ba2\u6237\u7aef\u9009\u9879\uff0c\u5305\u62ecOracle Instant Client\u3002Oracle Instant Client\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Oracle\u5ba2\u6237\u7aef\u5b9e\u73b0\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u4e0b\u8f7dOracle Instant Client<\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u4eceOracle\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7dOracle Instant Client\u3002\u9009\u62e9\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\uff0c\u901a\u5e38\u5305\u62ecBasic\u548cSQL*Plus\u7b49\u7ec4\u4ef6\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u89e3\u538b\u5230\u4e00\u4e2a\u5408\u9002\u7684\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u89e3\u538b\u4e4b\u540e\uff0c\u60a8\u9700\u8981\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6765\u786e\u4fddPython\u7a0b\u5e8f\u80fd\u591f\u627e\u5230Oracle\u5ba2\u6237\u7aef\u5e93\u3002\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u53f3\u952e\u70b9\u51fb\u201c\u6211\u7684\u7535\u8111\u201d\u6216\u201c\u6b64\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u9009\u62e9\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e0b\uff0c\u627e\u5230\u201cPath\u201d\u53d8\u91cf\uff0c\u5e76\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/li>\n<li>\u5c06Oracle Instant Client\u7684\u89e3\u538b\u76ee\u5f55\u6dfb\u52a0\u5230Path\u53d8\u91cf\u4e2d\u3002<\/li>\n<\/ul>\n<p><p>\u5728Unix\/Linux\u7cfb\u7edf\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u7f16\u8f91<code>~\/.bashrc<\/code>\u6587\u4ef6\u6765\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export LD_LIBRARY_PATH=\/path\/to\/oracle\/instantclient:$LD_LIBRARY_PATH<\/p>\n<p>export PATH=\/path\/to\/oracle\/instantclient:$PATH<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u914d\u7f6e\u8fde\u63a5\u5b57\u7b26\u4e32<\/p>\n<\/p>\n<p><p>\u8fde\u63a5Oracle\u6570\u636e\u5e93\u65f6\uff0c\u9700\u8981\u63d0\u4f9b\u8fde\u63a5\u5b57\u7b26\u4e32\u3002\u8fde\u63a5\u5b57\u7b26\u4e32\u901a\u5e38\u5305\u62ec\u7528\u6237\u540d\u3001\u5bc6\u7801\u3001\u6570\u636e\u5e93\u4e3b\u673a\u540d\u3001\u670d\u52a1\u540d\u7b49\u4fe1\u606f\u3002\u8fde\u63a5\u5b57\u7b26\u4e32\u6709\u591a\u79cd\u683c\u5f0f\uff0c\u5e38\u89c1\u7684\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-plaintext\">username\/password@hostname:port\/service_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f7f\u7528TNS\u540d\u79f0\uff0c\u53ef\u4ee5\u5c06\u8fde\u63a5\u5b57\u7b26\u4e32\u5199\u6210\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-plaintext\">username\/password@tnsname<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u60a8\u5df2\u7ecf\u5728<code>tnsnames.ora<\/code>\u6587\u4ef6\u4e2d\u914d\u7f6e\u4e86\u76f8\u5e94\u7684TNS\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528cx_Oracle\u8fde\u63a5Oracle\u6570\u636e\u5e93<\/p>\n<\/p>\n<p><p>\u8fde\u63a5\u5b57\u7b26\u4e32\u51c6\u5907\u597d\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528cx_Oracle\u5e93\u8fde\u63a5Oracle\u6570\u636e\u5e93\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cx_Oracle<\/p>\n<h2><strong>\u914d\u7f6e\u8fde\u63a5\u4fe1\u606f<\/strong><\/h2>\n<p>dsn = cx_Oracle.makedsn(&quot;hostname&quot;, 1521, service_name=&quot;servicename&quot;)<\/p>\n<p>username = &quot;your_username&quot;<\/p>\n<p>password = &quot;your_password&quot;<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/h2>\n<p>try:<\/p>\n<p>    connection = cx_Oracle.connect(user=username, password=password, dsn=dsn)<\/p>\n<p>    print(&quot;Connection established!&quot;)<\/p>\n<p>except cx_Oracle.DatabaseError as e:<\/p>\n<p>    error, = e.args<\/p>\n<p>    print(&quot;Oracle-Error-Code:&quot;, error.code)<\/p>\n<p>    print(&quot;Oracle-Error-Message:&quot;, error.message)<\/p>\n<h2><strong>\u6267\u884cSQL\u67e5\u8be2<\/strong><\/h2>\n<p>cursor = connection.cursor()<\/p>\n<p>cursor.execute(&quot;SELECT * FROM your_table&quot;)<\/p>\n<p>for row in cursor:<\/p>\n<p>    print(row)<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>cursor.close()<\/p>\n<p>connection.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5728\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c<code>makedsn<\/code>\u51fd\u6570\u7528\u4e8e\u751f\u6210\u6570\u636e\u6e90\u540d\u79f0\uff08DSN\uff09\uff0c\u5b83\u662f\u4e00\u4e2a\u5305\u542b\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\u7684\u5b57\u7b26\u4e32\u3002\u901a\u8fc7<code>connect<\/code>\u51fd\u6570\u4f7f\u7528\u7528\u6237\u540d\u3001\u5bc6\u7801\u548cDSN\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5\u3002\u6210\u529f\u5efa\u7acb\u8fde\u63a5\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6e38\u6807\uff08cursor\uff09\u5bf9\u8c61\u6267\u884cSQL\u67e5\u8be2\uff0c\u6700\u540e\u8bb0\u5f97\u5173\u95ed\u6e38\u6807\u548c\u8fde\u63a5\u4ee5\u91ca\u653e\u8d44\u6e90\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5904\u7406\u8fde\u63a5\u5f02\u5e38<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u53ef\u80fd\u4f1a\u51fa\u73b0\u5404\u79cd\u5f02\u5e38\u60c5\u51b5\uff0c\u4f8b\u5982\u7f51\u7edc\u4e2d\u65ad\u3001\u65e0\u6548\u7684\u7528\u6237\u540d\u6216\u5bc6\u7801\u7b49\u3002\u4e3a\u4e86\u63d0\u9ad8\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u5065\u58ee\u6027\uff0c\u5efa\u8bae\u5728\u4ee3\u7801\u4e2d\u5904\u7406\u53ef\u80fd\u7684\u5f02\u5e38\u3002cx_Oracle\u63d0\u4f9b\u4e86<code>DatabaseError<\/code>\u5f02\u5e38\u7c7b\uff0c\u53ef\u4ee5\u7528\u4e8e\u6355\u83b7\u6570\u636e\u5e93\u76f8\u5173\u7684\u9519\u8bef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    connection = cx_Oracle.connect(user=username, password=password, dsn=dsn)<\/p>\n<p>    print(&quot;Connection established!&quot;)<\/p>\n<p>except cx_Oracle.DatabaseError as e:<\/p>\n<p>    error, = e.args<\/p>\n<p>    print(&quot;Oracle-Error-Code:&quot;, error.code)<\/p>\n<p>    print(&quot;Oracle-Error-Message:&quot;, error.message)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u6355\u83b7\u5f02\u5e38\uff0c\u53ef\u4ee5\u83b7\u53d6\u9519\u8bef\u4ee3\u7801\u548c\u9519\u8bef\u6d88\u606f\uff0c\u4ece\u800c\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f18\u5316\u8fde\u63a5\u6027\u80fd<\/p>\n<\/p>\n<p><p>\u5728\u9ad8\u5e76\u53d1\u5e94\u7528\u4e2d\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u6027\u80fd\u53ef\u80fd\u4f1a\u6210\u4e3a\u74f6\u9888\u3002\u4e3a\u4e86\u63d0\u9ad8\u8fde\u63a5\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u4f18\u5316\u63aa\u65bd\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u8fde\u63a5\u6c60<\/strong>\uff1a\u8fde\u63a5\u6c60\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u51cf\u5c11\u8fde\u63a5\u5efa\u7acb\u548c\u91ca\u653e\u7684\u5f00\u9500\u3002cx_Oracle\u63d0\u4f9b\u4e86\u8fde\u63a5\u6c60\u529f\u80fd\uff0c\u4f7f\u7528<code>SessionPool<\/code>\u7c7b\u53ef\u4ee5\u521b\u5efa\u8fde\u63a5\u6c60\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cx_Oracle<\/p>\n<p>dsn = cx_Oracle.makedsn(&quot;hostname&quot;, 1521, service_name=&quot;servicename&quot;)<\/p>\n<p>pool = cx_Oracle.SessionPool(user=&quot;your_username&quot;, password=&quot;your_password&quot;, dsn=dsn, min=2, max=10, increment=1)<\/p>\n<p>connection = pool.acquire()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8c03\u6574\u8fde\u63a5\u6c60\u53c2\u6570<\/strong>\uff1a\u6839\u636e\u5e94\u7528\u7684\u5e76\u53d1\u9700\u6c42\uff0c\u5408\u7406\u8bbe\u7f6e\u8fde\u63a5\u6c60\u7684\u6700\u5c0f\u8fde\u63a5\u6570\uff08min\uff09\u3001\u6700\u5927\u8fde\u63a5\u6570\uff08max\uff09\u548c\u8fde\u63a5\u589e\u91cf\uff08increment\uff09\u7b49\u53c2\u6570\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u5316SQL\u67e5\u8be2<\/strong>\uff1a\u786e\u4fddSQL\u67e5\u8be2\u7684\u6267\u884c\u6548\u7387\uff0c\u5305\u62ec\u7d22\u5f15\u7684\u4f7f\u7528\u3001\u907f\u514d\u5168\u8868\u626b\u63cf\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u60a8\u5e94\u8be5\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528cx_Oracle\u5e93\u8fde\u63a5Oracle\u6570\u636e\u5e93\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u4e3b\u8981\u5305\u62ec\u5b89\u88c5cx_Oracle\u5e93\u3001\u914d\u7f6eOracle\u5ba2\u6237\u7aef\u3001\u6784\u5efa\u8fde\u63a5\u5b57\u7b26\u4e32\u3001\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5\u3001\u6267\u884cSQL\u67e5\u8be2\u4ee5\u53ca\u5904\u7406\u8fde\u63a5\u5f02\u5e38\u7b49\u5185\u5bb9\u3002\u4e3a\u4e86\u63d0\u5347\u5e94\u7528\u6027\u80fd\uff0c\u5efa\u8bae\u4f7f\u7528\u8fde\u63a5\u6c60\u5e76\u4f18\u5316SQL\u67e5\u8be2\u3002\u4f7f\u7528\u8fd9\u4e9b\u6280\u672f\uff0c\u60a8\u53ef\u4ee5\u5728Python\u5e94\u7528\u4e2d\u9ad8\u6548\u5730\u8fde\u63a5\u548c\u64cd\u4f5cOracle\u6570\u636e\u5e93\u3002\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Python\u4e0eOracle\u6570\u636e\u5e93\u7684\u8fde\u63a5\u6280\u672f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8fde\u63a5Oracle\u6570\u636e\u5e93\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u8fde\u63a5Oracle\u6570\u636e\u5e93\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528cx_Oracle\u5e93\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86cx_Oracle\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>pip install cx_Oracle<\/code>\u6765\u5b8c\u6210\u3002\u63a5\u4e0b\u6765\uff0c\u60a8\u9700\u8981\u914d\u7f6eOracle\u5ba2\u6237\u7aef\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u8fdb\u884c\u8fde\u63a5\uff1a<\/p>\n<pre><code class=\"language-python\">import cx_Oracle\n\ndsn = cx_Oracle.makedsn(&#39;hostname&#39;, port, service_name=&#39;service_name&#39;)\nconnection = cx_Oracle.connect(user=&#39;username&#39;, password=&#39;password&#39;, dsn=dsn)\n<\/code><\/pre>\n<p>\u786e\u4fdd\u5c06<code>hostname<\/code>\u3001<code>port<\/code>\u3001<code>service_name<\/code>\u3001<code>username<\/code>\u548c<code>password<\/code>\u66ff\u6362\u4e3a\u60a8\u7684\u5b9e\u9645\u6570\u636e\u5e93\u4fe1\u606f\u3002<\/p>\n<p><strong>\u4f7f\u7528Oracle\u6570\u636e\u5e93\u65f6\uff0c\u5982\u4f55\u5904\u7406\u8fde\u63a5\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Oracle\u6570\u636e\u5e93\u8fde\u63a5\u65f6\uff0c\u8fde\u63a5\u9519\u8bef\u53ef\u80fd\u7531\u591a\u79cd\u539f\u56e0\u5f15\u8d77\uff0c\u4f8b\u5982\u7f51\u7edc\u95ee\u9898\u3001\u9519\u8bef\u7684\u51ed\u636e\u6216Oracle\u670d\u52a1\u672a\u542f\u52a8\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528try-except\u5757\u6765\u6355\u83b7\u5f02\u5e38\u5e76\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">try:\n    connection = cx_Oracle.connect(user=&#39;username&#39;, password=&#39;password&#39;, dsn=dsn)\nexcept cx_Oracle.DatabaseError as e:\n    error, = e.args\n    print(&quot;Oracle Database Error:&quot;, error.message)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u80fd\u5e2e\u52a9\u60a8\u5feb\u901f\u8bc6\u522b\u95ee\u9898\u5e76\u91c7\u53d6\u76f8\u5e94\u63aa\u65bd\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u6267\u884cOracle SQL\u67e5\u8be2\uff1f<\/strong><br \/>\u5728\u6210\u529f\u8fde\u63a5Oracle\u6570\u636e\u5e93\u540e\uff0c\u60a8\u53ef\u4ee5\u6267\u884cSQL\u67e5\u8be2\u3002\u4f7f\u7528cursor\u5bf9\u8c61\u53ef\u4ee5\u65b9\u4fbf\u5730\u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">cursor = connection.cursor()\ncursor.execute(&quot;SELECT * FROM your_table&quot;)\nrows = cursor.fetchall()\nfor row in rows:\n    print(row)\ncursor.close()\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>your_table<\/code>\u66ff\u6362\u4e3a\u60a8\u8981\u67e5\u8be2\u7684\u5b9e\u9645\u8868\u540d\u3002\u786e\u4fdd\u5728\u64cd\u4f5c\u5b8c\u6210\u540e\u5173\u95edcursor\u4ee5\u91ca\u653e\u8d44\u6e90\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8fde\u63a5Oracle\u6570\u636e\u5e93\u53ef\u4ee5\u901a\u8fc7cx_Oracle\u5e93\u5b9e\u73b0\u3001\u9700\u8981\u5b89\u88c5Oracle\u5ba2\u6237\u7aef\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002 [&hellip;]","protected":false},"author":3,"featured_media":930278,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930277"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=930277"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930277\/revisions"}],"predecessor-version":[{"id":930279,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930277\/revisions\/930279"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/930278"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=930277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=930277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=930277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}