{"id":60223,"date":"2024-10-13T01:04:15","date_gmt":"2024-10-12T17:04:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/60223\/"},"modified":"2024-10-13T01:04:16","modified_gmt":"2024-10-12T17:04:16","slug":"c%e8%aa%9e%e8%a8%80%e4%b8%ad%e4%bd%bf%e7%94%a8oracle%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-c-oracle%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/60223\/","title":{"rendered":"C\u8a9e\u8a00\u4e2d\u4f7f\u7528Oracle\u6578\u64da\u5eab\u9023\u63a5 (c oracle\u6578\u64da\u5eab\u9023\u63a5)"},"content":{"rendered":"<h1 id=\"c%e8%aa%9e%e8%a8%80%e4%b8%ad%e4%bd%bf%e7%94%a8oracle%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-ARRdeYmNzY\">C\u8a9e\u8a00\u4e2d\u4f7f\u7528Oracle\u6578\u64da\u5eab\u9023\u63a5<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u8edf\u4ef6\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u666e\u904d\u3002Oracle\u6578\u64da\u5eab\u4f5c\u70ba\u4e00\u7a2e\u5f37\u5927\u7684\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u4f01\u696d\u7d1a\u61c9\u7528\u4e2d\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728C\u8a9e\u8a00\u4e2d\u9023\u63a5Oracle\u6578\u64da\u5eab\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u6b65\u9a5f\u3002<\/p>\n<h2 id=\"%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-ARRdeYmNzY\">\u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u7d93\u5b89\u88dd\u4e86Oracle\u6578\u64da\u5eab\u548cOracle Instant Client\u3002\u9019\u4e9b\u5de5\u5177\u5c07\u5e6b\u52a9\u60a8\u5728C\u8a9e\u8a00\u4e2d\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u3002<\/p>\n<ul>\n<li>\u4e0b\u8f09\u4e26\u5b89\u88ddOracle Instant Client\u3002<\/li>\n<li>\u8a2d\u7f6e\u74b0\u5883\u8b8a\u91cf\uff0c\u4f8b\u5982LD_LIBRARY_PATH\uff08Linux\uff09\u6216PATH\uff08Windows\uff09\uff0c\u4ee5\u4fbf\u80fd\u5920\u627e\u5230Oracle\u7684\u5eab\u6587\u4ef6\u3002<\/li>\n<li>\u78ba\u4fdd\u60a8\u7684C\u7de8\u8b6f\u5668\u80fd\u5920\u627e\u5230Oracle\u7684\u982d\u6587\u4ef6\u548c\u5eab\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<h2 id=\"%e9%80%a3%e6%8e%a5oracle%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%ad%a5%e9%a9%9f-ARRdeYmNzY\">\u9023\u63a5Oracle\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f<\/h2>\n<p>\u5728C\u8a9e\u8a00\u4e2d\u9023\u63a5Oracle\u6578\u64da\u5eab\u901a\u5e38\u6d89\u53ca\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u5305\u542b\u5fc5\u8981\u7684\u982d\u6587\u4ef6\u3002<\/li>\n<li>\u521d\u59cb\u5316Oracle\u74b0\u5883\u3002<\/li>\n<li>\u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5\u3002<\/li>\n<li>\u57f7\u884cSQL\u67e5\u8a62\u3002<\/li>\n<li>\u8655\u7406\u67e5\u8a62\u7d50\u679c\u3002<\/li>\n<li>\u95dc\u9589\u9023\u63a5\u4e26\u6e05\u7406\u8cc7\u6e90\u3002<\/li>\n<\/ol>\n<h3 id=\"%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a2%bc-ARRdeYmNzY\">\u793a\u4f8b\u4ee3\u78bc<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728C\u8a9e\u8a00\u4e2d\u9023\u63a5Oracle\u6578\u64da\u5eab\u4e26\u57f7\u884c\u67e5\u8a62\uff1a<\/p>\n<pre><code>\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;oci.h&gt;\n\nvoid checkError(sword status, OCIError *errhp) {\n    text errMsg[512];\n    sb4 errCode = 0;\n    if (status != OCI_SUCCESS) {\n        OCIErrorGet((dvoid *)errhp, (ub4)1, (text *)NULL, &amp;errCode, errMsg, (ub4)sizeof(errMsg), OCI_HTYPE_ERROR);\n        printf(\"Error - %sn\", errMsg);\n        exit(1);\n    }\n}\n\nint main() {\n    OCIEnv *envhp;\n    OCIError *errhp;\n    OCISvcCtx *svchp;\n    OCIHandleAlloc((dvoid *)0, (dvoid **)&amp;envhp, OCI_HTYPE_ENV, (size_t)0, (dvoid **)0);\n    OCIHandleAlloc((dvoid *)envhp, (dvoid **)&amp;errhp, OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0);\n    OCIHandleAlloc((dvoid *)envhp, (dvoid **)&amp;svchp, OCI_HTYPE_SVCCTX, (size_t)0, (dvoid **)0);\n\n    \/\/ \u9023\u63a5\u5230\u6578\u64da\u5eab\n    checkError(OCIServerAttach(svchp, errhp, (text *)\"\/\/localhost:1521\/orcl\", (sb4)strlen(\"\/\/localhost:1521\/orcl\"), 0), errhp);\n\n    \/\/ \u5728\u9019\u88e1\u57f7\u884cSQL\u67e5\u8a62...\n\n    \/\/ \u95dc\u9589\u9023\u63a5\n    OCIServerDetach(svchp, errhp, 0);\n    OCIHandleFree((dvoid *)svchp, OCI_HTYPE_SVCCTX);\n    OCIHandleFree((dvoid *)errhp, OCI_HTYPE_ERROR);\n    OCIHandleFree((dvoid *)envhp, OCI_HTYPE_ENV);\n    return 0;\n}\n<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-ARRdeYmNzY\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528C\u8a9e\u8a00\u9023\u63a5Oracle\u6578\u64da\u5eab\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\uff1a<\/p>\n<ul>\n<li>\u78ba\u4fdd\u4f7f\u7528\u6b63\u78ba\u7684Oracle\u5ba2\u6236\u7aef\u7248\u672c\uff0c\u8207\u60a8\u7684\u6578\u64da\u5eab\u7248\u672c\u76f8\u5339\u914d\u3002<\/li>\n<li>\u5728\u57f7\u884cSQL\u67e5\u8a62\u6642\uff0c\u6ce8\u610fSQL\u8a9e\u6cd5\u7684\u6b63\u78ba\u6027\u3002<\/li>\n<li>\u8655\u7406\u932f\u8aa4\u6642\uff0c\u61c9\u8a72\u4f7f\u7528OCIErrorGet\u51fd\u6578\u4f86\u7372\u53d6\u8a73\u7d30\u7684\u932f\u8aa4\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ARRdeYmNzY\">\u7e3d\u7d50<\/h2>\n<p>\u5728C\u8a9e\u8a00\u4e2d\u9023\u63a5Oracle\u6578\u64da\u5eab\u662f\u4e00\u500b\u76f8\u5c0d\u76f4\u63a5\u7684\u904e\u7a0b\uff0c\u53ea\u8981\u9075\u5faa\u6b63\u78ba\u7684\u6b65\u9a5f\u4e26\u8655\u7406\u597d\u932f\u8aa4\u3002\u9019\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5229\u7528Oracle\u6578\u64da\u5eab\u7684\u5f37\u5927\u529f\u80fd\u4f86\u69cb\u5efa\u9ad8\u6548\u7684\u61c9\u7528\u7a0b\u5e8f\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u90e8\u7f72\u60a8\u7684\u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u5404\u7a2e\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u60a8\u90fd\u53ef\u4ee5\u5728\u6211\u5011\u7684\u7db2\u7ad9\u4e0a\u627e\u5230\u5408\u9069\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728C\u8a9e\u8a00\u4e2d\u9023\u63a5Oracle\u6578\u64da\u5eab\uff0c\u638c\u63e1\u57fa\u672c\u6b65\u9a5f\u548c\u793a\u4f8b\u4ee3\u78bc\uff0c\u8f15\u9b06\u5be6\u73fe\u6578\u64da\u64cd\u4f5c\u8207\u67e5\u8a62\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-60223","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=60223"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60223\/revisions"}],"predecessor-version":[{"id":60224,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/60223\/revisions\/60224"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=60223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=60223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=60223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}