{"id":643,"date":"2019-08-16T11:02:20","date_gmt":"2019-08-16T03:02:20","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=643"},"modified":"2019-08-16T11:04:04","modified_gmt":"2019-08-16T03:04:04","slug":"oralce%e6%96%b9%e8%a8%80%e4%b8%8bpackage%e4%b8%93%e9%a2%98","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=643","title":{"rendered":"Oralce\u65b9\u8a00\u4e0bPackage\u4e13\u9898"},"content":{"rendered":"<h2>\u4e00\uff0e Package\u7684\u6982\u5ff5<\/h2>\n<pre><code>\u5728\u4e00\u4e2a\u5927\u578b\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u6709\u5f88\u591a\u6a21\u5757\uff0c\u800c\u6bcf\u4e2a\u6a21\u5757\u53c8\u6709\u81ea\u5df1\u7684\u8fc7\u7a0b\u3001\u51fd\u6570\u7b49\u3002\u800c\u8fd9\u4e9b\u8fc7\u7a0b\u3001\u51fd\u6570\u9ed8\u8ba4\u662f\u653e\u5728\u4e00\u8d77\u7684\uff08\u5982\u5728PL\/SQL\u4e2d\uff0c\u8fc7\u7a0b\u9ed8\u8ba4\u90fd\u662f\u653e\u5728\u4e00\u8d77 \u7684\uff0c\u5373Procedures\u4e2d\uff09\uff0c\u8fd9\u4e9b\u975e\u5e38\u4e0d\u65b9\u4fbf\u67e5\u8be2\u548c\u7ef4\u62a4\uff0c\u751a\u81f3\u4f1a\u53d1\u751f\u8bef\u5220\u9664\u7684\u4e8b\u4ef6\u3002<\/code><\/pre>\n<blockquote>\n<p>PL\/SQL\u4e3a\u4e86\u6ee1\u8db3\u7a0b\u5e8f\u6a21\u5757\u5316\u7684\u9700\u8981\uff0c\u5f15\u5165\u4e86\u5305\u7684\u6784\u9020\u3002\u901a\u8fc7\u4f7f\u7528\u5305\u5c31\u53ef\u4ee5\u5206\u7c7b\u7ba1\u7406\u8fc7\u7a0b\u548c\u51fd\u6570\u7b49\u3002<\/p>\n<\/blockquote>\n<ol>\n<li>\u5305\u662f\u4e00\u79cd\u6570\u636e\u5e93\u5bf9\u8c61\uff0c\u76f8\u5f53\u4e8e\u4e00\u4e2a\u5bb9\u5668\u3002\u5c06\u903b\u8f91\u4e0a\u76f8\u5173\u7684\u8fc7\u7a0b\u3001\u51fd\u6570\u3001\u53d8\u91cf\u3001\u5e38\u91cf\u548c\u6e38\u6807\u7ec4\u5408\u6210\u4e00\u4e2a\u66f4\u5927\u7684\u5355\u4f4d\u3002\u7528\u6237\u53ef\u4ee5\u4ece\u5176\u4ed6 PL\/SQL \u5757\u4e2d\u5bf9\u5176\u8fdb\u884c\u5f15\u7528<\/li>\n<li>\u5305\u7c7b\u4f3c\u4e8eC++\u548cJAVA\u8bed\u8a00\u4e2d\u7684\u7c7b\uff0c\u5176\u4e2d\u53d8\u91cf\u76f8\u5f53\u4e8e\u7c7b\u4e2d\u7684\u6210\u5458\u53d8\u91cf\uff0c\u8fc7\u7a0b\u548c\u51fd\u6570\u76f8\u5f53\u4e8e\u7c7b\u65b9\u6cd5\u3002\u628a\u76f8\u5173\u7684\u6a21\u5757\u5f52\u7c7b\u6210\u4e3a\u5305\uff0c\u53ef\u4f7f\u5f00\u53d1\u4eba\u5458\u5229\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u6cd5\u8fdb\u884c\u5f00\u53d1\uff0c\u5177\u6709\u9762\u5411\u5bf9\u8c61\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u7684\u7279\u70b9\uff0c<\/li>\n<li>PL\/SQL\u7684\u5305\u5177\u6709\u4fe1\u606f\u9690\u853d\u6027(information hiding)\uff0c\u4ec5\u5728\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u8bbe\u8ba1\u6709\u5173\u5c42\u53ef\u89c1\u3002\u53ef\u5c06\u8fc7\u7a0b\u8bf4\u660e\u548c\u8fc7\u7a0b\u4f53\u7ec4\u6210\u4e00\u4e2a\u7a0b\u5e8f\u5355\u4f4d\u3002\u4e5f\u53ef\u5c06\u8fc7\u7a0b\u8bf4\u660e\u4e0e\u5b83\u7684\u8fc7\u7a0b\u4f53\u5206\u5f00\u3002\u4e5f\u53ef\u5728\u5305\u4e2d\u5b9a\u4e49\u8fc7\u7a0b\uff0c\u800c\u8be5\u8fc7\u7a0b\u5728\u5305\u8bf4\u660e\u4e2d\u6ca1\u6709\u5b9a\u4e49\u8fc7\u7a0b\u8bf4\u660e\uff0c\u8fd9\u6837\u5b9a\u4e49\u7684\u8fc7\u7a0b\u4ec5\u5728\u5305\u5185\u4f7f\u7528\u3002<\/li>\n<li>\u5728PL\/SQL\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\uff0c\u4f7f\u7528\u5305\u4e0d\u4ec5\u53ef\u4ee5\u4f7f\u7a0b\u5e8f\u8bbe\u8ba1\u6a21\u5757\u5316\uff0c\u5bf9\u5916\u9690\u85cf\u5305\u5185\u6240\u4f7f\u7528\u7684\u4fe1\u606f\uff08\u901a\u8fc7\u4f7f\u7528\u79c1\u7528\u53d8\u91cf\uff09\uff0c\u800c\u5199\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\u3002<\/li>\n<\/ol>\n<blockquote>\n<p>\u4f18\u70b9\uff1a<\/p>\n<\/blockquote>\n<ol>\n<li>\u628a\u51fd\u6570\u548c\u5b58\u50a8\u8fc7\u7a0b\u8fdb\u884c\u5206\u95e8\u522b\u7c7b\uff0c\u4e0d\u540cpackage\u7684\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u91cd\u540d\uff0c\u53ef\u4ee5\u6709\u6548\u907f\u514d\u547d\u540d\u51b2\u7a81\u548c\u52a0\u5f3a\u6a21\u5757\u5316\u7ba1\u7406<\/li>\n<li>\u88ab\u7ec4\u5408\u5728\u4e00\u8d77\u7684\u76f8\u5173\u5bf9\u8c61\u7684\u96c6\u5408\uff0c\u5f53\u5305\u4e2d\u4efb\u4f55\u51fd\u6570\u6216\u8005\u5b58\u50a8\u8fc7\u7a0b\u88ab\u8c03\u7528\uff0c\u5305\u5c31\u4f1a\u88ab\u52a0\u8f7d\u5165\u5185\u5b58\uff0c\u5305\u4e2d\u7684\u4efb\u4f55\u51fd\u6570\u6216\u5b58\u50a8\u8fc7\u7a0b\u7684\u5b50\u7a0b\u5e8f\u8bbf\u95ee\u901f\u5ea6\u5c06\u5927\u5927\u52a0\u5feb\u3002<\/li>\n<\/ol>\n<p><strong>\u4e00\u4e2a\u5b8c\u6574\u7684Package\u5305\u62ec\u5305\u5934\uff08specification\uff09\u548c\u5305\u4f53\uff08body\uff09\u4e24\u4e2a\u90e8\u5206<\/strong><\/p>\n<h2>\u4e8c\uff0e   Package\u7684\u521b\u5efa<\/h2>\n<ol>\n<li>\u53ea\u6709\u5f53\u5305\u5934\u7f16\u8f91\u6210\u529f\u540e\u624d\u80fd\u7f16\u8f91\u5305\u4f53.\u5176\u4e2d\u7684\u51fd\u6570\u540d\u4e0e\u8fc7\u7a0b\u540d\u987b\u548c\u5305\u5934\u4e2d\u7684\u51fd\u6570\u8fc7\u7a0b\u4e00\u6837.  <\/li>\n<li>\u5305\u8bf4\u660e\u548c\u5305\u4f53\u5fc5\u987b\u6709\u76f8\u540c\u7684\u540d\u5b57  <\/li>\n<li>\u5305\u7684\u5f00\u59cb\u6ca1\u6709begin\u8bed\u53e5\uff0c\u4e0e\u5b58\u50a8\u8fc7\u7a0b\u548c\u51fd\u6570\u4e0d\u540c\u3002  <\/li>\n<li>\u5728\u5305\u7684\u8bf4\u660e\u90e8\u5206\u5b9a\u4e49\u51fd\u6570\u548c\u8fc7\u7a0b\u7684\u540d\u79f0\u548c\u53c2\u6570\uff0c\u5177\u4f53\u5b9e\u73b0\u5728\u5305\u4f53\u4e2d\u5b9a\u4e49\u3002  <\/li>\n<li>\u5728\u5305\u5185\u58f0\u660e\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u7c7b\u578b\u5b9a\u4e49\u3001\u5f02\u5e38\u3001\u53ca\u6e38\u6807\u65f6\u4e0d\u4f7f\u7528declare\u3002  <\/li>\n<li>\u5305\u5185\u7684\u8fc7\u7a0b\u548c\u51fd\u6570\u7684\u5b9a\u4e49\u4e0d\u8981create or replace\u8bed\u53e5\u3002  <\/li>\n<li>\u5305\u58f0\u660e\u548c\u5305\u4f53\u4e24\u8005\u5206\u79bb\u3002<\/li>\n<\/ol>\n<h3>1.  \u8bed\u6cd5<\/h3>\n<h4>1.1    \u521b\u5efa\u5305\u5934<\/h4>\n<pre><code class=\"language-sql\">CREATE [OR REPLACE] PACKAGE package_name\n{IS | AS}\n    [\u516c\u6709\u6570\u636e\u7c7b\u578b\u5b9a\u4e49]\n    [\u516c\u6709\u6e38\u6807\u58f0\u660e]\n    [\u516c\u6709\u53d8\u91cf\u3001\u5e38\u91cf\u58f0\u660e]\n    [\u516c\u6709\u5b50\u7a0b\u5e8f\u58f0\u660e]\nEND;<\/code><\/pre>\n<blockquote>\n<p>A. \u5305\u5934\u4e2d\u76f4\u63a5\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u5747\u4e3a\u5168\u5c40\u53d8\u91cf\uff0c\u53ef\u4ee5\u5728\u5305\u5916\u4f7f\u7528\u3002<br \/>\nB.  \u5305\u5934\u4e2d\u4ec5\u58f0\u660e\u8fc7\u7a0b\uff0c\u51fd\u6570\uff0cRECORD\uff0cCollections\u7b49\u7684\u7c7b\u578b<\/p>\n<\/blockquote>\n<h4>1.2 \u521b\u5efa\u5305\u4f53<\/h4>\n<pre><code class=\"language-sql\">CREATE [OR REPLACE] PACKAGE BODY package_name\n{IS | AS}\n    [\u79c1\u6709\u6570\u636e\u7c7b\u578b\u5b9a\u4e49]\n    [\u79c1\u6709\u53d8\u91cf\u3001\u5e38\u91cf\u58f0\u660e]\n    [\u79c1\u6709\u5b50\u7a0b\u5e8f\u58f0\u660e\u548c\u5b9a\u4e49]\n    [\u516c\u6709\u5b50\u7a0b\u5e8f\u5b9a\u4e49]\nBEGIN\n    \u6267\u884c\u90e8\u5206(\u521d\u59cb\u5316\u90e8\u5206)\nEND;<\/code><\/pre>\n<blockquote>\n<p>A. \u5305\u4f53\u4e2d\u76f4\u63a5\u5b9a\u4e49\u7684\u53d8\u91cf\u5747\u4e3a\u5c40\u90e8\u53d8\u91cf\uff0c\u53ea\u80fd\u5728\u5305\u5185\u4f7f\u7528<br \/>\nB.  \u5305\u4f53\u4e2d\u5177\u4f53\u5b9a\u4e49\u8fc7\u7a0b\uff0c\u51fd\u6570\uff0cRECORD\u7c7b\u578b\u7684\u53d8\u91cf\u7b49<\/p>\n<\/blockquote>\n<h4>1.3 \u5305\u7684\u8c03\u7528<\/h4>\n<pre><code class=\"language-sql\">Package-name.type-name\nPackage-name.procedure-name\nPackage-name.function-name\n...<\/code><\/pre>\n<blockquote>\n<p>Package-name \u662f\u7a0b\u5e8f\u5305\u540d\u79f0\uff0c<br \/>\ntype-name\u662f\u5305\u5185\u58f0\u660e\u7684\u7c7b\u578b\u540d\u79f0\uff0c<br \/>\nprocedure-name\u662f\u5305\u5185\u58f0\u660e\u7684\u8fc7\u7a0b\u540d\u79f0\uff0c<br \/>\nfunction-name \u662f\u5305\u5185\u58f0\u660e\u7684\u51fd\u6570\u540d\u79f0<\/p>\n<\/blockquote>\n<h3>2.  \u5b9e\u4f8b<\/h3>\n<h4>2.1    \u521b\u5efa\u5305\u5934<\/h4>\n<pre><code class=\"language-sql\">-- \u521b\u5efa\u4e00\u4e2a\u540d\u4e3atest\u7684\u5305\u5934\u3002\nCREATE OR REPLACE PACKAGE test\nIS\n    -- \u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3atransid\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u7c7b\u578b\u4e3astring\u3002\n    transid STRING\n    -- \u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3al_row\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u7c7b\u578b\u4e3aint\u3002\n    l_row int := 1\n    -- \u58f0\u660e\u4e00\u4e2a\u540d\u4e3atest_procedure\u7684\u8fc7\u7a0b\uff0c\u5f62\u53c2\u540d\u4e3atest_name\uff0c\u7c7b\u578b\u4e3a\u5b57\u7b26\u4e32\u3002\n    -- \u58f0\u660e\u4e00\u4e2a\u540d\u4e3aaa_type\u7684NESTED TABLE\u7c7b\u578b\uff0c\u7528\u6765\u5b58\u653e\u6574\u6570\u578b\u7684\u6570\u636e\u3002\n    TYPE aa_type IS TABLE OF INTEGER\nEND;\n\/<\/code><\/pre>\n<h4>2.2    \u521b\u5efa\u5305\u4f53<\/h4>\n<pre><code class=\"language-sql\">-- \u58f0\u660e\u4e00\u4e2a\u540d\u4e3atest\u7684\u5305\u4f53\uff0c\u6b64\u5904\u5fc5\u987b\u4e0e\u5305\u5934\u540d\u4e00\u81f4\u3002\nCREATE OR REPLACE PACKAGE body test\nIS\n    -- \u5177\u4f53\u5b9a\u4e49\u8fc7\u7a0btest_procedure\u7684\u5185\u5bb9\u3002\n    PROCEDURE test_procedure(test_name string) IS\n    BEGIN\n        dbms_output.put_line(test_name ||'\u662f\u4e2a\u597d\u540c\u5b66\uff01')\n    END\nEND;\n\/<\/code><\/pre>\n<h4>2.3    \u5305\u7684\u8c03\u7528<\/h4>\n<pre><code class=\"language-sql\">DECLARE\n    -- \u58f0\u660e\u4e00\u4e2a\u5305\u5185NESTED TABLE\u7c7b\u578baa_type\u7684\u53d8\u91cfv_aa_type\u3002\n    v_aa_type test.aa_type:=test.aa_type()\nBEGIN\n    -- \u7ed9\u53d8\u91cfv_aa_type\u5206\u914d\u7a7a\u95f4\u3002\n    v_aa_type.extend(3)\n    -- \u4f9d\u6b21\u7ed9\u53d8\u91cfv_aa_type\u8d4b\u503c\u3002\n    v_aa_type(1) := '1001'\n    v_aa_type(2) := '2001'\n    v_aa_type(3):= '3001'\n    -- \u4f9d\u6b21\u6253\u5370\u51fa\u53d8\u91cfv_aa_type\u91cc\u7684\u503c\u3002\n    FOR i IN 1..v_aa_type.count()\n    LOOP\n        dbms_output.put_line(v_aa_type(i))\n    END LOOP;\n    test.test_procedure('\u5f20\u4e09')\nEND;\n\/<\/code><\/pre>\n<h2>\u4e09\uff0e   Package\u7684\u8c03\u7528<\/h2>\n<blockquote>\n<p>Inceptor\u4e2d\uff0c\u5728\u521b\u5efaPackages\u7684\u65f6\u5019\u53ef\u4ee5\u4ec5\u521b\u5efa\u5305\u5934\u4e0d\u7528\u518d\u521b\u5efa\u5305\u4f53\uff1b\u4f46\u662f\u521b\u5efa\u5305\u4f53\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u8981\u6709\u4e00\u4e2a\u76f8\u540c\u540d\u5b57\u7684\u5305\u5934\u7684\u5b58\u5728\u3002<\/p>\n<\/blockquote>\n<h3>1.  \u4ec5\u521b\u5efa\u5305\u5934<\/h3>\n<h4>1.1 \u521b\u5efa\u4e00\u4e2a\u540d\u4e3aaa_pkg\u7684\u5305\u5934\uff0c\u5728\u5305\u5185\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3aaa_type\u7684\u8868\u7c7b\u578b<\/h4>\n<pre><code class=\"language-sql\">-- \u521b\u5efa\u4e00\u4e2a\u540d\u4e3aaa_pkg\u7684\u5305\u5934\u3002\nCREATE OR REPLACE PACKAGE aa_pkg IS\n    -- \u521b\u5efa\u5305\u5185\u7c7b\u578bNESTED TABLE\u7c7b\u578b\uff0c\u540d\u4e3aaa_type\u3002\n    TYPE aa_type IS TABLE OF INTEGER\nEND;\n\/<\/code><\/pre>\n<h4>1.2 \u521b\u5efa\u4e00\u4e2a\u540d\u4e3aprint_aa\u7684\u8fc7\u7a0b\uff0c\u4f9d\u6b21\u6253\u5370\u51fa\u8868\u7c7b\u578b\u53d8\u91cf\u4e2d\u7684\u503c<\/h4>\n<pre><code class=\"language-sql\">CREATE OR REPLACE PROCEDURE print_aa (aa aa_pkg.aa_type) IS\n-- \u5b9a\u4e49\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\u7684\u53d8\u91cfi\u3002\ni INT\nBEGIN\n    -- \u4f7f\u7528\u96c6\u5408\u5143\u7d20\u65b9\u6cd5FIRST()\u548cNEXT(i)\uff0c\u4f9d\u6b21\u6253\u5370\u51faaa\u5185\u7684\u503c\u3002\n    i := aa.FIRST()\n    WHILE i IS NOT NULL LOOP\n        DBMS_OUTPUT.PUT_LINE (i ||' '||aa(i))\n        i := aa.NEXT(i)\n    END LOOP;\nEND;\n\/<\/code><\/pre>\n<h4>1.3    \u521b\u5efa\u4e00\u4e2aaa_pkg.aa_type\u7c7b\u578b\u7684\u53d8\u91cf\u4e3aaa_var<\/h4>\n<pre><code class=\"language-sql\">-- \u7ed9\u53d8\u91cfaa_var\u5206\u914d\u5927\u5c0f\u4e3a3\u7684\u7a7a\u95f4\u3002\n-- \u4f9d\u6b21\u7ed9\u53d8\u91cfaa_var\u8d4b\u503c\u3002\n-- \u5229\u7528\u8fc7\u7a0bprint_aa\u6253\u5370\u51fa\u53d8\u91cf\u7684\u503c\u3002\n!set plsqlUseSlash true\nDECLARE\n    -- \u521b\u5efa\u4e00\u4e2a\u7c7b\u578b\u4e3aaa_pkg\u5305\u5185\u7c7b\u578baa_type\u7684\u53d8\u91cfaa_var\uff0c\u5e76\u521d\u59cb\u5316\u3002\n    aa_var aa_pkg.aa_type:=aa_pkg.aa_type()\nBEGIN\n    aa_var.extend(3)\n    aa_var(1) := '1001'\n    aa_var(2) := '2001'\n    aa_var(3):= '3001'\n    print_aa(aa_var)\nEND;\n\/<\/code><\/pre>\n<h3>2.  \u521b\u5efa\u5305\u5934\u548c\u5305\u4f53<\/h3>\n<h4>2.1 \u521b\u5efa\u4e00\u4e2a\u540d\u4e3atestpackage\u7684\u5305\u5934<\/h4>\n<pre><code class=\"language-sql\">-- \u521b\u5efa\u4e00\u4e2a\u540d\u4e3atestpackage\u7684\u5305\u5934\u3002\nCREATE OR REPLACE PACKAGE testpackage\nIS\n    -- \u58f0\u660e\u4e00\u4e2a\u540d\u4e3arecord_type\u7684\u8bb0\u5f55\u7c7b\u578b\uff0c\u5206\u91cf\u540d\u5206\u522b\u4e3atrans_time\uff0cprice\uff0c\u5206\u91cf\u7c7b\u578b\u5206\u522b\u4e3astring,double\u3002\n    TYPE record_type IS RECORD(trans_time STRING, price DOUBLE)\n    -- \u58f0\u660e\u4e00\u4e2a\u540d\u4e3acur\u7684\u52a8\u6001\u6e38\u6807\u3002\n    TYPE cur IS REF CURSOR\n    -- \u58f0\u660e\u4e00\u4e2a\u540d\u4e3atestprocedure()\u7684\u8fc7\u7a0b\uff0c\u4e14\u4e0d\u5e26\u53c2\u6570\u3002\n    PROCEDURE testprocedure()\nEND;\n\/<\/code><\/pre>\n<h4>2.2 \u521b\u5efa\u4e00\u4e2a\u540d\u4e3atestpackage\u7684\u5305\u4f53<\/h4>\n<pre><code class=\"language-sql\">-- \u521b\u5efa\u4e00\u4e2a\u540d\u4e3atestpackage\u7684\u5305\u4f53\uff0c\u6b64\u5904\u548c\u5305\u5934\u540d\u76f8\u540c\u3002\nCREATE OR REPLACE PACKAGE BODY testpackage\nIS\n    -- \u5b9a\u4e49\u4e00\u4e2a\u7c7b\u578b\u4e3arecord_type\u7684\u53d8\u91cfv_record_type\u3002\n    v_record_type record_type\n    -- \u5b9a\u4e49\u4e00\u4e2a\u6e38\u6807\u7c7b\u578b\u4e3acur\u7684\u6e38\u6807\u53d8\u91cfsqlcur\u3002\n    sqlcur cur\n    -- \u5177\u4f53\u5b9a\u4e49\u8fc7\u7a0btestprocedure()\u7684\u5185\u5bb9\u3002\n    PROCEDURE testprocedure() IS\nBEGIN\n    -- \u6253\u5f00\u6e38\u6807sqlcur\uff0c\u53bb\u67e5\u8be2\u8868transactions\u4e2d\u4ea4\u6613\u53f7\u4e3a943197522\u7684\u4ea4\u6613\u65f6\u95f4\u548c\u4ef7\u683c\u3002\n    OPEN sqlcur FOR\n        SELECT trans_time,price     FROM transactions WHERE trans_id=943197522;\n    LOOP\n        -- \u5c06\u6e38\u6807\u67e5\u8be2\u5230\u7684\u7ed3\u679c\u653e\u8fdb\u53d8\u91cfv_record_type\u91cc\u3002\n        FETCH sqlcur INTO v_record_type\n            -- \u5982\u679c\u6e38\u6807\u6ca1\u6709\u67e5\u8be2\u5230\u7ed3\u679c\uff0c\u5c31\u9000\u51fa\u3002\n            EXIT WHEN sqlcur%notfound\n            -- \u8f93\u51fa\u53d8\u91cfv_record_type\u7684\u5206\u91cftrans_time\u548c\u5206\u91cfprice\u7684\u503c\u3002\n            dbms_output.put_line(v_record_type.trans_time||' '||v_record_type.price)\n    END LOOP;\n    -- \u5173\u95ed\u6e38\u6807\u3002\n    CLOSE sqlcur\n    END;\nEND;\n\/<\/code><\/pre>\n<h4>2.3 \u8c03\u7528\u5305\u5185\u51fd\u6570<\/h4>\n<pre><code class=\"language-sql\">BEGIN\n    -- \u8c03\u7528\u5305\u5185\u8fc7\u7a0btestpackage.testprocedure()\uff0c\u6b64\u5904\u4e0d\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528testprocedure()\u3002\n    testpackage.testprocedure()\nEND;\n\/<\/code><\/pre>\n<h2>\u56db\uff0eInceptor\u9884\u5b9a\u4e49\u5305<\/h2>\n<h3>1.dbms_output<\/h3>\n<blockquote>\n<p>Inceptor\u4e2d\uff0c\u5305dbms_output\u662f\u7cfb\u7edf\u9884\u5b9a\u4e49\u7684\uff0c<strong>\u5305\u5185\u53ea\u6709\u4e00\u4e2a\u540d\u4e3aput_line\u7684\u8fc7\u7a0b<\/strong>\uff0c\u4e14put_line\u8fc7\u7a0b\u4e5f\u662f\u7cfb\u7edf\u9884\u5b9a\u4e49\u7684\u3002<\/p>\n<p>\u5728\u5b9e\u9645\u7684\u4f7f\u7528\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u8fc7\u7a0bput_line\u6253\u5370\u7ed3\u679c\uff0c\u4e5f\u53ef\u4ee5\u8c03\u7528\u5305\u5185\u8fc7\u7a0bput_line\u6765\u6253\u5370\u7ed3\u679c\u3002<\/p>\n<\/blockquote>\n<pre><code class=\"language-sql\">BEGIN\n    FOR test IN 1..5 LOOP\n        dbms_output.put_line('test:'||test)\n    END LOOP;\nEND;\n\/<\/code><\/pre>\n<h3>2.owa_util<\/h3>\n<blockquote>\n<p>\u5728\u64b0\u5199ETL\u8c03\u5ea6\u5de5\u5177\u65f6\uff0c\u5728\u5f80\u65e5\u5fd7\u8868\u91cc\u9762\u5199\u8c03\u5ea6\u65e5\u5fd7\u65f6\uff0c\u9700\u8981\u5199\u5165\u5f53\u524d\u6267\u884c\u7684\u7528\u6237\u540d\u79f0\u3001\u6267\u884c\u4f5c\u4e1a\u7684\u540d\u79f0\u7b49\u4fe1\u606f\uff0c\u6240\u4ee5\u5c31\u60f3\u5230\u4e86OWA_UTIL.WHO_CALLED_ME\u8fd9\u4e2a\u8fc7\u7a0b\u3002<\/p>\n<\/blockquote>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Parameter<\/th>\n<th style=\"text-align: left;\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">owner<\/td>\n<td style=\"text-align: left;\">The owner of the program unit.&#8211;\u7a0b\u5e8f\u5355\u5143\u7684\u6240\u6709\u8005\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">name<\/td>\n<td style=\"text-align: left;\">The name of the program unit. This is the name of the package, if the calling program unit is wrapped in a package, or the name of the procedure or function if the calling program unit is a standalone procedure or function. If the calling program unit is part of an anonymous block, this is NULL.&#8211;\u7a0b\u5e8f\u5355\u5143\u7684\u540d\u79f0\u3002\u8fd9\u662f\u5305\u7684\u540d\u79f0(\u5982\u679c\u8c03\u7528\u7a0b\u5e8f\u5355\u5143\u5305\u88c5\u5728\u5305\u4e2d)\uff0c\u6216\u8005\u662f\u8fc7\u7a0b\u6216\u51fd\u6570\u7684\u540d\u79f0(\u5982\u679c\u8c03\u7528\u7a0b\u5e8f\u5355\u5143\u662f\u72ec\u7acb\u7684\u8fc7\u7a0b\u6216\u51fd\u6570)\u3002\u5982\u679c\u8c03\u7528\u7a0b\u5e8f\u5355\u5143\u662f\u533f\u540d\u5757\u7684\u4e00\u90e8\u5206\uff0c\u5219\u8be5\u503c\u4e3aNULL\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">lineno<\/td>\n<td style=\"text-align: left;\">The line number within the program unit where the call was made.&#8211;\u8c03\u7528\u6240\u5728\u7a0b\u5e8f\u5355\u5143\u4e2d\u7684\u884c\u53f7\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">caller_t<\/td>\n<td style=\"text-align: left;\">The type of program unit that made the call. The possibilities are: package body, anonymous block, procedure, and function. Procedure and function are only for standalone procedures and functions.&#8211;\u53d1\u51fa\u8c03\u7528\u7684\u7a0b\u5e8f\u5355\u5143\u7684\u7c7b\u578b\u3002\u53ef\u80fd\u6027\u6709:\u5305\u4f53\u3001\u533f\u540d\u5757\u3001\u8fc7\u7a0b\u548c\u51fd\u6570\u3002\u8fc7\u7a0b\u548c\u51fd\u6570\u4ec5\u7528\u4e8e\u72ec\u7acb\u7684\u8fc7\u7a0b\u548c\u51fd\u6570\u3002\u8fd9\u4e00\u70b9\u5f88\u91cd\u8981\uff0c\u5982\u679c\u8fc7\u7a0b\u5728\u5305\u91cc\u9762\uff0c\u8fd4\u56de\u7684\u662f\u5305\u540d\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-sql\">-- \u521b\u5efa\u4e00\u4e2a\u540d\u4e3aouter_proc()\u7684\u8fc7\u7a0b\u3002\nCREATE OR REPLACE PROCEDURE outer_proc()\nIS\n    -- \u5206\u522b\u58f0\u660e\u56db\u4e2a\u53d8\u91cf\u3002\n    v_owner STRING\n    v_name STRING\n    v_lineno INT\n    v_type STRING\nBEGIN\n    DBMS_OUTPUT.PUT_LINE('Outer outer proc')\n    -- \u8c03\u7528\u5305\u5185\u8fc7\u7a0bowa_util.who_called_me\uff0c\u5176\u4e2dv_owner, v_name, v_lineno,\n    v_type\u5206\u522b\u7528\u6765\u50a8\u5b58\u76f8\u5bf9\u5e94\u5f62\u53c2\u6240\u83b7\u5f97\u7684\u503c\u3002\n    owa_util.who_called_me(v_owner, v_name, v_lineno, v_type)\n    -- \u4f9d\u6b21\u8f93\u51fa\u56db\u4e2a\u53d8\u91cf\u7684\u503c\u3002\n    DBMS_OUTPUT.PUT_LINE('Owner: ' || v_owner)\n    DBMS_OUTPUT.PUT_LINE('Name: ' || v_name)\n    DBMS_OUTPUT.PUT_LINE('Lineno: ' || v_lineno)\n    DBMS_OUTPUT.PUT_LINE('Type: ' || v_type)\nEND;\n\/<\/code><\/pre>\n<pre><code class=\"language-sql\">BEGIN\nouter_proc()\nEND;\n\/<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/\/nj.transwarp.cn:8180\/wp-content\/uploads\/2019\/08\/image-1565924478768.png\" alt=\"file\" \/><\/p>\n<blockquote>\n<p><strong>\u901a\u8fc7\u7ed3\u679c\u6765\u770b\uff0cown_util\u5305\u5f62\u540c\u865a\u8bbe<\/strong><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\uff0e Package\u7684\u6982\u5ff5 \u5728\u4e00\u4e2a\u5927\u578b\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u6709\u5f88\u591a\u6a21\u5757\uff0c\u800c\u6bcf\u4e2a\u6a21\u5757\u53c8\u6709\u81ea\u5df1\u7684\u8fc7\u7a0b\u3001\u51fd\u6570\u7b49\u3002\u800c\u8fd9\u4e9b\u8fc7\u7a0b\u3001\u51fd ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=643\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-643","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=643"}],"version-history":[{"count":0,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/643\/revisions"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}