{"id":94678,"date":"2024-10-19T20:15:18","date_gmt":"2024-10-19T12:15:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/94678\/"},"modified":"2024-10-19T20:15:19","modified_gmt":"2024-10-19T12:15:19","slug":"oraclepl%e5%be%9e%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e5%a6%82%e4%bd%95%e8%ae%80%e5%8f%96blob%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/94678\/","title":{"rendered":"OraclePL\u5f9e\u6578\u64da\u5eab\u4e2d\u5982\u4f55\u8b80\u53d6BLOB\u5b57\u6bb5"},"content":{"rendered":"<h1 id=\"oracle-pl-sql-%e5%be%9e%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e5%a6%82%e4%bd%95%e8%ae%80%e5%8f%96-blob-%e5%ad%97%e6%ae%b5-zsoEGzaAlV\">Oracle PL\/SQL \u5f9e\u6578\u64da\u5eab\u4e2d\u5982\u4f55\u8b80\u53d6 BLOB \u5b57\u6bb5<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0cBLOB\uff08Binary Large Object\uff09\u662f\u4e00\u7a2e\u7528\u65bc\u5b58\u5132\u5927\u91cf\u4e8c\u9032\u5236\u6578\u64da\u7684\u6578\u64da\u985e\u578b\uff0c\u901a\u5e38\u7528\u65bc\u5b58\u5132\u5716\u50cf\u3001\u97f3\u983b\u3001\u8996\u983b\u6216\u5176\u4ed6\u5927\u578b\u6587\u4ef6\u3002Oracle \u6578\u64da\u5eab\u63d0\u4f9b\u4e86\u5f37\u5927\u7684 PL\/SQL \u8a9e\u8a00\u4f86\u64cd\u4f5c\u9019\u4e9b\u6578\u64da\u985e\u578b\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 Oracle PL\/SQL \u5f9e\u6578\u64da\u5eab\u4e2d\u8b80\u53d6 BLOB \u5b57\u6bb5\uff0c\u4e26\u63d0\u4f9b\u76f8\u95dc\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"blob-%e5%ad%97%e6%ae%b5%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-zsoEGzaAlV\">BLOB \u5b57\u6bb5\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>BLOB \u5b57\u6bb5\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u6578\u64da\u985e\u578b\uff0c\u80fd\u5920\u5b58\u5132\u6700\u5927\u53ef\u9054 4GB \u7684\u4e8c\u9032\u5236\u6578\u64da\u3002\u9019\u4f7f\u5f97\u5b83\u975e\u5e38\u9069\u5408\u7528\u65bc\u5b58\u5132\u591a\u5a92\u9ad4\u6587\u4ef6\u3002\u8207\u5176\u4ed6\u6578\u64da\u985e\u578b\u76f8\u6bd4\uff0cBLOB \u7684\u8655\u7406\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\uff0c\u56e0\u70ba\u5b83\u5011\u4e0d\u9069\u5408\u76f4\u63a5\u5728 SQL \u67e5\u8a62\u4e2d\u9032\u884c\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e8%ae%80%e5%8f%96-blob-%e5%ad%97%e6%ae%b5%e7%9a%84%e6%ad%a5%e9%a9%9f-zsoEGzaAlV\">\u8b80\u53d6 BLOB \u5b57\u6bb5\u7684\u6b65\u9a5f<\/h2>\n<p>\u5728 Oracle \u6578\u64da\u5eab\u4e2d\uff0c\u8b80\u53d6 BLOB \u5b57\u6bb5\u901a\u5e38\u9700\u8981\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u5efa\u7acb\u9023\u63a5\u5230\u6578\u64da\u5eab\u3002<\/li>\n<li>\u57f7\u884c\u67e5\u8a62\u4ee5\u7372\u53d6 BLOB \u6578\u64da\u3002<\/li>\n<li>\u4f7f\u7528 PL\/SQL \u4ee3\u78bc\u4f86\u8655\u7406\u548c\u8b80\u53d6 BLOB \u6578\u64da\u3002<\/li>\n<\/ul>\n<h3 id=\"1-%e5%bb%ba%e7%ab%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-zsoEGzaAlV\">1. \u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5efa\u7acb\u8207 Oracle \u6578\u64da\u5eab\u7684\u9023\u63a5\u3002\u9019\u53ef\u4ee5\u901a\u904e\u4f7f\u7528 Oracle \u7684 JDBC \u9a45\u52d5\u7a0b\u5e8f\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u9023\u63a5\u793a\u4f8b\uff1a<\/p>\n<pre><code>import java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.SQLException;\n\npublic class DatabaseConnection {\n    public static Connection getConnection() throws SQLException {\n        String url = \"jdbc:oracle:thin:@localhost:1521:xe\";\n        String user = \"your_username\";\n        String password = \"your_password\";\n        return DriverManager.getConnection(url, user, password);\n    }\n}\n<\/code><\/pre>\n<h3 id=\"2-%e5%9f%b7%e8%a1%8c%e6%9f%a5%e8%a9%a2%e4%bb%a5%e7%8d%b2%e5%8f%96-blob-%e6%95%b8%e6%93%9a-zsoEGzaAlV\">2. \u57f7\u884c\u67e5\u8a62\u4ee5\u7372\u53d6 BLOB \u6578\u64da<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u57f7\u884c SQL \u67e5\u8a62\u4f86\u7372\u53d6\u5305\u542b BLOB \u6578\u64da\u7684\u8a18\u9304\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u67e5\u8a62\u793a\u4f8b\uff1a<\/p>\n<pre><code>String sql = \"SELECT blob_column FROM your_table WHERE id = ?\";\nPreparedStatement pstmt = connection.prepareStatement(sql);\npstmt.setInt(1, yourId);\nResultSet rs = pstmt.executeQuery();\n<\/code><\/pre>\n<h3 id=\"3-%e8%ae%80%e5%8f%96-blob-%e6%95%b8%e6%93%9a-zsoEGzaAlV\">3. \u8b80\u53d6 BLOB \u6578\u64da<\/h3>\n<p>\u4e00\u65e6\u7372\u53d6\u4e86\u7d50\u679c\u96c6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 PL\/SQL \u4f86\u8b80\u53d6 BLOB \u6578\u64da\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\u4ee3\u78bc\uff0c\u5c55\u793a\u5982\u4f55\u8b80\u53d6 BLOB \u4e26\u5c07\u5176\u5beb\u5165\u6587\u4ef6\uff1a<\/p>\n<pre><code>if (rs.next()) {\n    Blob blob = rs.getBlob(\"blob_column\");\n    InputStream inputStream = blob.getBinaryStream();\n    FileOutputStream outputStream = new FileOutputStream(\"output_file\");\n    \n    byte[] buffer = new byte[1024];\n    int bytesRead = -1;\n    \n    while ((bytesRead = inputStream.read(buffer)) != -1) {\n        outputStream.write(buffer, 0, bytesRead);\n    }\n    \n    outputStream.close();\n    inputStream.close();\n}\n<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-zsoEGzaAlV\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u8655\u7406 BLOB \u6578\u64da\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8003\u616e\uff1a<\/p>\n<ul>\n<li>\u78ba\u4fdd\u9069\u7576\u7684\u6b0a\u9650\uff1a\u78ba\u4fdd\u7528\u6236\u64c1\u6709\u8b80\u53d6 BLOB \u6578\u64da\u7684\u6b0a\u9650\u3002<\/li>\n<li>\u6027\u80fd\u8003\u91cf\uff1a\u7531\u65bc BLOB \u6578\u64da\u901a\u5e38\u8f03\u5927\uff0c\u8acb\u8003\u616e\u4f7f\u7528\u6d41\u5f0f\u8655\u7406\u4f86\u907f\u514d\u5167\u5b58\u554f\u984c\u3002<\/li>\n<li>\u932f\u8aa4\u8655\u7406\uff1a\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c\u61c9\u8a72\u6dfb\u52a0\u9069\u7576\u7684\u932f\u8aa4\u8655\u7406\u6a5f\u5236\uff0c\u4ee5\u61c9\u5c0d\u53ef\u80fd\u51fa\u73fe\u7684\u7570\u5e38\u60c5\u6cc1\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-zsoEGzaAlV\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u4f7f\u7528 Oracle PL\/SQL \u5f9e\u6578\u64da\u5eab\u4e2d\u8b80\u53d6 BLOB \u5b57\u6bb5\u3002\u9019\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u578b\u4e8c\u9032\u5236\u6578\u64da\u7684\u61c9\u7528\u7a0b\u5e8f\u4f86\u8aaa\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728Oracle PL\u4e2d\u6709\u6548\u8b80\u53d6\u6578\u64da\u5eab\u4e2d\u7684BLOB\u5b57\u6bb5\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\u8207\u6027\u80fd\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-94678","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94678","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=94678"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94678\/revisions"}],"predecessor-version":[{"id":94679,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94678\/revisions\/94679"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=94678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=94678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=94678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}