{"id":4820,"date":"2021-06-17T15:03:57","date_gmt":"2021-06-17T07:03:57","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=4820"},"modified":"2024-05-23T14:22:59","modified_gmt":"2024-05-23T06:22:59","slug":"%e5%85%b3%e4%ba%8epl-sql%e5%87%bd%e6%95%b0%e5%92%8cpl-sql%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e5%8f%af%e4%bb%a5%e9%87%8d%e5%90%8d%e7%9a%84%e9%97%ae%e9%a2%98%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=4820","title":{"rendered":"\u5173\u4e8ePL\/SQL\u51fd\u6570\u548cPL\/SQL\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u91cd\u540d\u7684\u95ee\u9898\u8bf4\u660e"},"content":{"rendered":"<h3>\u95ee\u9898\u63cf\u8ff0<\/h3>\n<hr \/>\n<p>\u5ba2\u6237\u5728\u901a\u8fc7 <code>system.procedures_v<\/code> \u6216\u8005 <code>system.functions_v<\/code> \u67e5\u770b\u5b58\u50a8\u8fc7\u7a0b\u6216\u8005\u51fd\u6570\u65f6\uff0c\u53d1\u73b0\u5927\u91cf\u7684\u540c\u540d\u5b58\u50a8\u8fc7\u7a0b\u548c\u51fd\u6570\u3002\u65e0\u6cd5\u786e\u8ba4\u8c03\u7528\u7684\u662f\u54ea\u4e2a\uff0c\u8c03\u7528\u65f6\u4e5f\u5bb9\u6613\u51fa\u73b0\u8c03\u7528\u9519\u8bef\u7684\u95ee\u9898\u3002<\/p>\n<p>\u672c\u6587\u4e3b\u8981\u4ece\u539f\u7406\u89d2\u5ea6\u89e3\u91ca\u4e0b\u8be5\u95ee\u9898\u5b58\u5728\u7684\u539f\u56e0\uff0c\u4ee5\u53ca\u89c4\u907f\u65b9\u6cd5\u3002<\/p>\n<p><font color=red>\u6ce8\u610f\uff1a\u6211\u4eec\u662f\u652f\u6301\u5b58\u50a8\u8fc7\u7a0b\u540c\u540d\u540c\u53c2\uff0c\u4f46\u662f\u9700\u8981\u4e0d\u540c\u7684database\uff0c\u6216\u8005\u4e0d\u540c\u7684package\u4e0b\u9762\u3002<\/font><\/p>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<h4>1. \u83b7\u53d6 inceptor \u4e2d\u89c6\u56fe\u7684DDL\uff0c\u901a\u8fc7 dblink \u6307\u5411 txsql \u7684\u89c6\u56fe<\/h4>\n<pre><code class=\"language-sql\">--system.procedures_v\uff0c\u6307\u5411txsql\u7684metastore_inceptorX.procedures_v\nCREATE VIEW system.procedures_v AS \nselect \n    plsql_function_name(procedure_name) <code>procedure_name<\/code>,\n    plsql_parameters(procedure_name) <code>parameters<\/code>,\n    full_text,\n    owner_name,\n    owner_type,\n    create_time,\n    database_name \nfrom <code>procedures_v<\/code>@<code>system_dblink<\/code>;<\/code><\/pre>\n<pre><code class=\"language-sql\">--system.functions_v\uff0c\u6307\u5411txsql\u7684metastore_inceptorX.functions_v\nCREATE VIEW system.functions_v AS \nselect \n    plsql_function_name(function_name) <code>function_name<\/code>,\n    plsql_parameters(function_name) <code>parameters<\/code>,\n    full_text,\n    owner_name,\n    owner_type,\n    create_time,\n    database_name \nfrom <code>functions_v<\/code>@<code>system_dblink<\/code>;<\/code><\/pre>\n<h4>2. \u83b7\u53d6txsql\u4e2d\u89c6\u56fe\u7684DDL\uff0c\u6307\u5411\u5143\u6570\u636e\u8868FUNCS<\/h4>\n<pre><code class=\"language-sql\">--metastore_inceptorX.procedures_v\uff0c\u6307\u5411\u5143\u6570\u636e\u7684FUNCS\u548cDBS\nCREATE ALGORITHM=UNDEFINED DEFINER=<code>inceptoruser<\/code>@<code>%<\/code> SQL SECURITY DEFINER VIEW procedures_v\n(procedure_id, procedure_name, full_text, owner_name, owner_type, create_time, database_name) AS\nSELECT\n    <code>FUNCS<\/code>.<code>FUNC_ID<\/code>                    AS <code>procedure_id<\/code>,\n    <code>FUNCS<\/code>.<code>FUNC_NAME<\/code>                  AS <code>procedure_name<\/code>,\n    <code>FUNCS<\/code>.<code>FULL_TEXT<\/code>                  AS <code>full_text<\/code>,\n    <code>FUNCS<\/code>.<code>OWNER_NAME<\/code>                 AS <code>owner_name<\/code>,\n    <code>FUNCS<\/code>.<code>OWNER_TYPE<\/code>                 AS <code>owner_type<\/code>,\n    from_unixtime(<code>FUNCS<\/code>.<code>CREATE_TIME<\/code>) AS <code>create_time<\/code>,\n    <code>DBS<\/code>.<code>NAME<\/code>                         AS <code>database_name<\/code>\nFROM\n    (<code>FUNCS<\/code>\nJOIN\n    <code>DBS<\/code>\nON\n    ((\n            <code>FUNCS<\/code>.<code>DB_ID<\/code> = <code>DBS<\/code>.<code>DB_ID<\/code>)))\nWHERE\n    (\n        <code>FUNCS<\/code>.<code>FUNC_TYPE<\/code> = 2);<\/code><\/pre>\n<pre><code class=\"language-sql\">--metastore_inceptorX.functions_v\uff0c\u6307\u5411\u5143\u6570\u636e\u7684FUNCS\u548cDBS\nCREATE ALGORITHM=UNDEFINED DEFINER=<code>inceptoruser<\/code>@<code>%<\/code> SQL SECURITY DEFINER VIEW functions_v\n(function_id, function_name, full_text, owner_name, owner_type, create_time, database_name) AS\nSELECT\n    <code>FUNCS<\/code>.<code>FUNC_ID<\/code>                    AS <code>function_id<\/code>,\n    <code>FUNCS<\/code>.<code>FUNC_NAME<\/code>                  AS <code>function_name<\/code>,\n    <code>FUNCS<\/code>.<code>FULL_TEXT<\/code>                  AS <code>full_text<\/code>,\n    <code>FUNCS<\/code>.<code>OWNER_NAME<\/code>                 AS <code>owner_name<\/code>,\n    <code>FUNCS<\/code>.<code>OWNER_TYPE<\/code>                 AS <code>owner_type<\/code>,\n    from_unixtime(<code>FUNCS<\/code>.<code>CREATE_TIME<\/code>) AS <code>create_time<\/code>,\n    <code>DBS<\/code>.<code>NAME<\/code>                         AS <code>database_name<\/code>\nFROM\n    (<code>FUNCS<\/code>\nJOIN\n    <code>DBS<\/code>\nON\n    ((\n            <code>FUNCS<\/code>.<code>DB_ID<\/code> = <code>DBS<\/code>.<code>DB_ID<\/code>)))\nWHERE\n    (\n        <code>FUNCS<\/code>.<code>FUNC_TYPE<\/code> = 1);<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5b58\u50a8\u8fc7\u7a0b\u548c\u51fd\u6570\u5bf9\u5e94\u7684\u5143\u6570\u636e\u8868\u662f\u540c\u4e00\u4e2a<code>FUNCS<\/code>\uff0c\u53ea\u662f<code>FUNC_TYPE<\/code>\u7684\u533a\u522b\uff08<code>FUNC_TYPE<\/code>\u4e3a1\u662f\u51fd\u6570\uff0c2\u4e3a\u5b58\u50a8\u8fc7\u7a0b\uff09\u3002<\/p>\n<h4>3. \u83b7\u53d6\u5143\u6570\u636e\u8868FUNCS\u7684DDL<\/h4>\n<pre><code class=\"language-sql\">CREATE TABLE\n    FUNCS\n    (\n        FUNC_ID bigint NOT NULL,\n        CREATE_TIME INT NOT NULL,\n        DB_ID bigint,\n        FUNC_NAME VARCHAR(255) COLLATE utf8_bin,\n        FUNC_TYPE INT NOT NULL,\n        OWNER_NAME VARCHAR(128) COLLATE latin1_bin,\n        OWNER_TYPE VARCHAR(10) COLLATE latin1_bin,\n        FULL_TEXT mediumtext COLLATE utf8_bin,\n        FUNC_DESC mediumblob NOT NULL,\n        CLASS_NAME VARCHAR(4000) COLLATE latin1_bin,\n        PRIMARY KEY (FUNC_ID),\n        CONSTRAINT FUNCS_FK1 FOREIGN KEY (DB_ID) REFERENCES <code>DBS<\/code> (<code>DB_ID<\/code>),\n        CONSTRAINT UNIQUEFUNCTION UNIQUE (FUNC_NAME, DB_ID),\n        INDEX FUNCS_N49 (DB_ID)\n    )\n    ENGINE=InnoDB DEFAULT CHARSET=latin1 DEFAULT COLLATE=latin1_swedish_ci;<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c<code>FUNCS<\/code>\u8868\u7684<code>FUNC_NAME<\/code>\u548c<code>DB_ID<\/code>\u5b57\u6bb5\u662f\u4f5c\u4e3a\u8054\u5408\u552f\u4e00\u952e\u7684\uff0c\u6309\u7406\u8bf4\u4e00\u4e2a\u6570\u636e\u5e93<code>DB_ID<\/code>\u4e0b\u5e94\u8be5\u53ea\u6709\u4e00\u4e2a<code>FUNC_NAME<\/code>\u624d\u5bf9\uff0c\u4f46\u662f\uff0c\u6211\u4eec\u68c0\u67e5\u4e00\u4e0b<code>FUNCS.FUNC_NAME<\/code>\u5b57\u6bb5\u4f1a\u53d1\u73b0\u5f02\u6837\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/12\/image-1607674365155.png\" alt=\"file\" \/><\/p>\n<p>_z16_d7<font color=blue>default<\/font>p0<font color=red>ppp01<\/font><font color=green>stringstringstringstringstringstringstringstringstringstringstring<\/font><br \/>\n_z16_d7<font color=blue>default<\/font>p0<font color=red>ppp01<\/font><font color=green>stringstringstringstringstringstringstringstringstringstringstringstring<\/font><\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c<code>FUNC_NAME<\/code>\u5b57\u6bb5\u662f&quot;\u6570\u636e\u5e93\u540d\u79f0&quot;+&quot;\u51fd\u6570\u540d\u79f0&quot;+&quot;N\u4e2a\u53c2\u6570\u7c7b\u578b&quot;+&quot;\u5176\u4ed6\u5b57\u7b26&quot;\u62fc\u63a5\u800c\u6210\u7684\uff0c\u56fe\u4e2d\u7ea2\u6846\u90e8\u5206\uff0c\u5e93\u540d\u4e3a<code>default<\/code>\uff0c\u51fd\u6570\u540d\u79f0\u4e3a<code>ppp01<\/code>,\u4e00\u4e2a\u51fd\u6570\u4f7f\u7528\u4e86<code>11<\/code>\u4e2a\u53c2\u6570\uff0c\u53c2\u6570\u7c7b\u578b\u4e3a<code>string<\/code>\uff0c\u800c\u53e6\u5916\u4e00\u4e2a\u540c\u5e93\u540c\u540d\u51fd\u6570\u4f7f\u7528\u4e86<code>12<\/code>\u4e2a\u53c2\u6570\uff0c\u8fd9\u6837\u5728\u4f7f\u7528\u7684\u65f6\u5019\u591a\u5199\u4e00\u4e2a\u53c2\u6570\u6216\u8005\u5c11\u5199\u4e00\u4e2a\u53c2\u6570\u5c31\u4f1a\u8c03\u7528\u9519\u8bef\u3002<\/p>\n<h4>\u89e3\u51b3\u65b9\u6cd5<\/h4>\n<hr \/>\n<p>\u521b\u5efa\u51fd\u6570\u65f6\uff0c<font color=red>\u53c2\u6570\u6570\u91cf\u4e0d\u4e00\u81f4\u6216\u8005\u53c2\u6570\u7c7b\u578b\u4e0d\u540c\uff08\u5305\u542b\u5165\u53c2\u548c\u51fa\u53c2\uff09\u90fd\u4f1a\u5f15\u53d1\u8be5\u95ee\u9898<\/font>\uff0c\u800c\u4e14<code>CREATE OR REPLACE<\/code>\u7684\u65b9\u5f0f\u53ea\u80fd\u591f\u628a\u76f8\u540c\u5165\u53c2\u6570\u91cf\u3001\u76f8\u540c\u5165\u53c2\u7c7b\u578b\u7684\u51fd\u6570\u66ff\u4ee3\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u8fd9\u7c7b\u540c\u5e93\u540c\u540d\u7684\u51fd\u6570\/\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5efa\u8bae\u4f7f\u7528<code>DROP FUNCTION {IF EXISTS} ...<\/code>\/<code>DROP PROCEDURE {IF EXISTS} ...<\/code>\u7684\u65b9\u5f0f\u5220\u9664\u91cd\u5efa\uff0c\u800c\u4e0d\u5efa\u8bae\u4f7f\u7528<code>CREATE OR REPLACE FUNCTION ...<\/code>\/<code>CREATE OR REPLACE PROCEDURE ...<\/code>\u7684\u65b9\u5f0f\u3002<\/p>\n<h4>FAQ<\/h4>\n<p><strong>\u540c\u540d\u4e0d\u540c\u53c2\u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5982\u4f55\u6307\u5b9a\u4efb\u610f\u4e00\u4e2a\u8fdb\u884c\u5220\u9664\uff1f<\/strong><\/p>\n<pre><code class=\"language-sql\">-- \u521b\u5efa\n!set plsqlUseSlash true\nCREATE OR REPLACE PROCEDURE param1(var1 IN  string)\nIS\nBEGIN\n    PUT_LINE('hello world');\nEND;\n\/\n\n- \u5220\u9664\ndrop plsql procedure param1(var1 IN string);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u63cf\u8ff0 \u5ba2\u6237\u5728\u901a\u8fc7 system.procedures_v \u6216\u8005 system.functions_v \u67e5\u770b ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=4820\" 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":[40],"tags":[],"class_list":["post-4820","post","type-post","status-publish","format-standard","hentry","category-sql_issue"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/4820","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=4820"}],"version-history":[{"count":3,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/4820\/revisions"}],"predecessor-version":[{"id":13078,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/4820\/revisions\/13078"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}