{"id":638,"date":"2025-01-01T11:06:25","date_gmt":"2025-01-01T03:06:25","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=638"},"modified":"2025-01-01T11:06:25","modified_gmt":"2025-01-01T03:06:25","slug":"%e6%8a%a5%e9%94%99%ef%bc%9apls-00428%ef%bc%9a%e6%ad%a4-select-%e8%af%ad%e5%8f%a5%e4%b8%ad%e7%bc%ba%e5%b0%91-into-%e5%ad%90%e5%8f%a5%ef%bc%8c%e6%80%8e%e4%b9%88%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/01\/01\/%e6%8a%a5%e9%94%99%ef%bc%9apls-00428%ef%bc%9a%e6%ad%a4-select-%e8%af%ad%e5%8f%a5%e4%b8%ad%e7%bc%ba%e5%b0%91-into-%e5%ad%90%e5%8f%a5%ef%bc%8c%e6%80%8e%e4%b9%88%e8%a7%a3%e5%86%b3%ef%bc%9f\/","title":{"rendered":"\u62a5\u9519\uff1aPLS-00428\uff1a\u6b64 SELECT \u8bed\u53e5\u4e2d\u7f3a\u5c11 INTO \u5b50\u53e5\uff0c\u600e\u4e48\u89e3\u51b3\uff1f"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><code>PLS-00428\uff1a\u6b64 SELECT \u8bed\u53e5\u4e2d\u7f3a\u5c11 INTO \u5b50\u53e5<\/code> \u9519\u8bef\u901a\u5e38\u53d1\u751f\u5728 <strong>PL\/SQL<\/strong> \u5757\u4e2d\u6267\u884c <code>SELECT<\/code> \u67e5\u8be2\u65f6\uff0c\u4f46\u662f\u67e5\u8be2\u7ed3\u679c\u6ca1\u6709\u6b63\u786e\u5730\u5b58\u5165\u53d8\u91cf\u6216\u6e38\u6807\u3002\u7b80\u5355\u6765\u8bf4\uff0cOracle \u7684 PL\/SQL \u5f15\u64ce\u8981\u6c42\u4f60\u5728 <code>SELECT<\/code> \u67e5\u8be2\u65f6\u6307\u5b9a <code>INTO<\/code> \u5b50\u53e5\uff0c\u7528\u4e8e\u63a5\u6536\u67e5\u8be2\u7ed3\u679c\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u9519\u8bef\u539f\u56e0<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 PL\/SQL \u4e2d\uff0c\u5982\u679c\u4f60\u6267\u884c\u4e00\u4e2a <code>SELECT<\/code> \u67e5\u8be2\u5e76\u671f\u671b\u8fd4\u56de\u4e00\u4e2a\u7ed3\u679c\uff0c\u4f60\u5fc5\u987b\u4f7f\u7528 <code>INTO<\/code> \u5b50\u53e5\u6765\u5c06\u67e5\u8be2\u7ed3\u679c\u5b58\u50a8\u5230\u4e00\u4e2a\u6216\u591a\u4e2a\u53d8\u91cf\u4e2d\u3002\u5982\u679c\u4f60\u6ca1\u6709\u8fd9\u6837\u505a\uff0cOracle \u5c31\u4f1a\u629b\u51fa <code>PLS-00428<\/code> \u9519\u8bef\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u51b3\u65b9\u6cd5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u4f60\u67e5\u8be2\u7684\u8fd4\u56de\u7c7b\u578b\u548c\u6570\u91cf\uff0c\u6b63\u786e\u4f7f\u7528 <code>INTO<\/code> \u5b50\u53e5\u6765\u63a5\u6536\u67e5\u8be2\u7ed3\u679c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>\u5355\u884c\u67e5\u8be2<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c <code>SELECT<\/code> \u67e5\u8be2\u53ea\u8fd4\u56de\u4e00\u884c\u6570\u636e\uff0c\u4f60\u9700\u8981\u5c06\u7ed3\u679c\u5b58\u5165\u4e00\u4e2a\u6216\u591a\u4e2a\u53d8\u91cf\u4e2d\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DECLARE\n    v_name VARCHAR2(100);\n    v_age  NUMBER;\nBEGIN\n    -- \u6b63\u786e\u7684 SELECT \u8bed\u53e5\uff0c\u4f7f\u7528 INTO \u5b50\u53e5\n    SELECT name, age\n    INTO v_name, v_age\n    FROM employees\n    WHERE employee_id = 1001;\n\n    -- \u8f93\u51fa\u7ed3\u679c\n    DBMS_OUTPUT.PUT_LINE('Name: ' || v_name || ', Age: ' || v_age);\nEND;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>SELECT<\/code> \u67e5\u8be2\u8fd4\u56de\u4e86 <code>name<\/code> \u548c <code>age<\/code>\uff0c\u5e76\u5c06\u7ed3\u679c\u5206\u522b\u5b58\u50a8\u5230 <code>v_name<\/code> \u548c <code>v_age<\/code> \u53d8\u91cf\u4e2d\u3002<strong>\u6ce8\u610f\uff1a<\/strong> <code>INTO<\/code> \u5b50\u53e5\u5728\u8fd9\u91cc\u975e\u5e38\u91cd\u8981\uff0c\u5b83\u786e\u4fdd\u67e5\u8be2\u7684\u7ed3\u679c\u5b58\u50a8\u5230 PL\/SQL \u53d8\u91cf\u4e2d\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>\u591a\u884c\u67e5\u8be2<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u9884\u8ba1 <code>SELECT<\/code> \u67e5\u8be2\u4f1a\u8fd4\u56de\u591a\u884c\u7ed3\u679c\uff0c\u4e0d\u80fd\u76f4\u63a5\u5c06\u5176\u653e\u5165\u53d8\u91cf\u4e2d\u3002\u4f60\u9700\u8981\u4f7f\u7528\u6e38\u6807\u6765\u5904\u7406\u591a\u884c\u67e5\u8be2\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DECLARE\n    CURSOR emp_cursor IS\n        SELECT name, age\n        FROM employees;\n    v_name  employees.name%TYPE;\n    v_age   employees.age%TYPE;\nBEGIN\n    OPEN emp_cursor;\n    LOOP\n        FETCH emp_cursor INTO v_name, v_age;\n        EXIT WHEN emp_cursor%NOTFOUND;\n        DBMS_OUTPUT.PUT_LINE('Name: ' || v_name || ', Age: ' || v_age);\n    END LOOP;\n    CLOSE emp_cursor;\nEND;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528\u4e86\u6e38\u6807 <code>emp_cursor<\/code> \u6765\u5904\u7406\u591a\u884c\u67e5\u8be2\u3002\u6bcf\u6b21\u901a\u8fc7 <code>FETCH<\/code> \u83b7\u53d6\u4e00\u884c\u6570\u636e\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728 <code>v_name<\/code> \u548c <code>v_age<\/code> \u53d8\u91cf\u4e2d\u3002\u4f60\u5fc5\u987b\u4f7f\u7528 <code>LOOP<\/code> \u548c <code>EXIT<\/code> \u8bed\u53e5\u6765\u9010\u884c\u5904\u7406\u67e5\u8be2\u7ed3\u679c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong>\u5982\u679c\u67e5\u8be2\u6ca1\u6709\u7ed3\u679c<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u67e5\u8be2\u6ca1\u6709\u8fd4\u56de\u4efb\u4f55\u7ed3\u679c\u65f6\uff0cPL\/SQL \u4f1a\u629b\u51fa <code>NO_DATA_FOUND<\/code> \u9519\u8bef\u3002\u5982\u679c\u4f60\u5e0c\u671b\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528\u5f02\u5e38\u5904\u7406\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DECLARE\n    v_name VARCHAR2(100);\n    v_age  NUMBER;\nBEGIN\n    BEGIN\n        -- \u53ef\u80fd\u6ca1\u6709\u6570\u636e\u7684\u67e5\u8be2\n        SELECT name, age\n        INTO v_name, v_age\n        FROM employees\n        WHERE employee_id = 9999;  -- \u5047\u8bbe\u8fd9\u4e2a ID \u4e0d\u5b58\u5728\n    EXCEPTION\n        WHEN NO_DATA_FOUND THEN\n            DBMS_OUTPUT.PUT_LINE('No data found for the given employee ID');\n    END;\nEND;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u5e38\u89c1\u9519\u8bef\u573a\u666f\u548c\u89e3\u51b3\u65b9\u6cd5<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5fd8\u8bb0\u4f7f\u7528 <code>INTO<\/code> \u5b50\u53e5<\/strong>\uff1a \u9519\u8bef\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT name, age FROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT name, age INTO v_name, v_age FROM employees;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u67e5\u8be2\u8fd4\u56de\u591a\u4e2a\u7ed3\u679c\u65f6\u6ca1\u6709\u4f7f\u7528\u6e38\u6807<\/strong>\uff1a \u9519\u8bef\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT name, age INTO v_name, v_age FROM employees;  -- \u5982\u679c\u6709\u591a\u884c\u7ed3\u679c\uff0c\u62a5\u9519<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u65b9\u6cd5\uff1a<br>\u4f7f\u7528\u6e38\u6807\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   DECLARE\n       CURSOR emp_cursor IS\n           SELECT name, age FROM employees;\n       v_name VARCHAR2(100);\n       v_age  NUMBER;\n   BEGIN\n       OPEN emp_cursor;\n       LOOP\n           FETCH emp_cursor INTO v_name, v_age;\n           EXIT WHEN emp_cursor%NOTFOUND;\n           DBMS_OUTPUT.PUT_LINE('Name: ' || v_name || ', Age: ' || v_age);\n       END LOOP;\n       CLOSE emp_cursor;\n   END;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>PLS-00428\uff1a\u6b64 SELECT \u8bed\u53e5\u4e2d\u7f3a\u5c11 INTO \u5b50\u53e5<\/code> \u9519\u8bef\u662f\u7531\u4e8e\u4f60\u5728\u6267\u884c <code>SELECT<\/code> \u67e5\u8be2\u65f6\u6ca1\u6709\u6307\u5b9a <code>INTO<\/code> \u5b50\u53e5\u6765\u63a5\u6536\u67e5\u8be2\u7ed3\u679c\u3002\u4f60\u9700\u8981\u786e\u4fdd\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e\u5355\u884c\u67e5\u8be2\uff0c\u4f7f\u7528 <code>INTO<\/code> \u5b50\u53e5\u5c06\u67e5\u8be2\u7ed3\u679c\u5b58\u5165\u53d8\u91cf\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u591a\u884c\u67e5\u8be2\uff0c\u4f7f\u7528\u6e38\u6807\u6765\u5904\u7406\u67e5\u8be2\u7ed3\u679c\u3002<\/li>\n\n\n\n<li>\u5728\u6ca1\u6709\u7ed3\u679c\u65f6\uff0c\u9002\u5f53\u5904\u7406 <code>NO_DATA_FOUND<\/code> \u5f02\u5e38\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u4fee\u590d\u8fd9\u4e9b\u95ee\u9898\uff0c\u4f60\u5c31\u80fd\u89e3\u51b3 <code>PLS-00428<\/code> \u9519\u8bef\uff0c\u6b63\u786e\u6267\u884c PL\/SQL \u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PLS-00428\uff1a\u6b64 SELECT \u8bed\u53e5\u4e2d\u7f3a\u5c11 INTO \u5b50\u53e5 \u9519\u8bef\u901a\u5e38\u53d1\u751f\u5728 PL\/SQL \u5757\u4e2d\u6267\u884c SE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-638","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=638"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/638\/revisions"}],"predecessor-version":[{"id":639,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/638\/revisions\/639"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}