【问题标题】:PL/SQL Procedure SELECT Input- Error PLS-00306PL/SQL Procedure SELECT Input- Error PLS-00306
【发布时间】:2022-12-02 04:15:52
【问题描述】:

Hello I'm a beginner at PL/SQL and some help would be appreciated.

So I have this procedure here and my goal is to have it so that when this procedure is executed that I can enter a 5 digit integer (a zipcode) and it will just select those values from the table and display just as if I've done a query like

SELECT * FROM customers WHERE customer_zipcode = "input zipcode".

create or replace PROCEDURE LIST_CUSTOMER_ZIPCODE(
p_zipcode IN customers.customer_zipcode%TYPE,
p_disp OUT SYS_REFCURSOR)
-- User input Variable, Display Variable
IS
BEGIN
    OPEN p_disp for SELECT customer_first_name, customer_zipcode FROM customers 
    WHERE customer_zipcode=p_zipcode;
EXCEPTION
    -- Input Sanitization
    WHEN no_data_found THEN
    dbms_output.put_line('-1');
END;



EXEC LIST_CUSTOMER_ZIPCODE(07080);


When I execute this command I just keep getting this error.

[enter image description here](https://i.stack.imgur.com/nCI8T.png)

【问题讨论】:

    标签: oracle stored-procedures plsql


    【解决方案1】:

    You can't justexecutesuch a procedure as it expects 2 parameters; one is IN, while another is OUT (ref cursor which contains result set).

    I don't have your tables so I'll demonstrate it using Scott's sample schema by passing department number and returning list of employees working in that department.

    Procedure:

    SQL> set serveroutput on
    SQL> create or replace procedure p_list
      2    (p_deptno    in dept.deptno%type,
      3     p_disp     out sys_refcursor
      4    )
      5  is
      6  begin
      7    open p_disp for select ename, job from emp
      8                    where deptno = p_deptno;
      9  end;
     10  /
    
    Procedure created.
    

    This is how you use it:

    SQL> declare
      2    l_list   sys_refcursor;
      3    l_ename  emp.ename%type;
      4    l_job    emp.job%type;
      5  begin
      6    p_list(10, l_list);       --> calling the procedure; use 2 parameters
      7
      8    loop
      9      fetch l_list into l_ename, l_job;
     10      exit when l_list%notfound;
     11      dbms_output.put_line(l_ename ||' - '|| l_job);
     12    end loop;
     13  end;
     14  /
    CLARK - MANAGER
    KING - PRESIDENT
    MILLER - CLERK
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    【讨论】:

      猜你喜欢
      • 2014-06-25
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      相关资源
      最近更新 更多