如何在 oracle 10g 中创建/调用过程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10869821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:52:48  来源:igfitidea点击:

How to create/call procedure in oracle 10g?

oraclestored-procedures

提问by yogesh patel

I created a procedure in Oracle but am getting an error when I attempt to execute it. Below are listed the steps I am taking to create this procedure:

我在 Oracle 中创建了一个过程,但在尝试执行它时出现错误。下面列出了我为创建此过程而采取的步骤:

SQL> ed getuserinfo

create or replace procedure getUserInfo
    ( p_username out Users.username%TYPE,
      p_password out Users.password%TYPE ) IS
BEGIN

    select username,password into p_username,p_password from users where username='yogi';

END;
/


SQL> exec getuserinfo
BEGIN getuserinfo; END;

          *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'GETUSERINFO' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

What is the problem and how can I solve it? Olease can anyone help me?

有什么问题,我该如何解决?Olease 任何人都可以帮助我吗?

回答by Ben

You need to actually create the procedure, which you haven't done. You need a semi-colon after endand if you're creating it in SQL*Plus you need to add /to inform SQL*Plus that the block is finished:

您需要实际创建程序,而您还没有这样做。后面需要一个分号end,如果是在 SQL*Plus 中创建它,则需要添加/以通知 SQL*Plus 块已完成:

create or replace procedure getUserInfo
      ( p_username out Users.username%TYPE,
        p_password out Users.password%TYPE ) IS
BEGIN

select username,password into p_username,p_password from users;

END;
/
show error

It's always wise to add show errorafterwards as well so that any errors are returned to the console in an understandable format.

show error之后添加总是明智的,以便任何错误都以可理解的格式返回到控制台。

回答by DCookie

Did you actually execute your create procedure statement? Did you get a "Procedure created." message? The fact that Oracle does not know of your getuserinfo procedure indicates to me that this statement was not performed.

你真的执行了你的 create procedure 语句吗?您是否收到了“程序已创建”。信息?Oracle 不知道您的 getuserinfo 过程这一事实向我表明未执行此语句。

回答by user3056758

I think it's procedure calling mistake!! Calling Should be like below:

我认为是程序调用错误!!呼叫应如下所示:

SQL>var var1 varchar2(50);
SQL>var var2 varchar2(50);
SQL> exec getuserinfo(:var1, :var2); 
SQL> print var1, var2; 

Have Fun!!

玩得开心!!

回答by Sebas

You need to specify the out parameters when you call the procedure.

调用过程时需要指定输出参数。

DECLARE
    x Users.username%TYPE;
    y Users.password%TYPE;
BEGIN
    getuserinfo(x, y);
    DBMS_OUTPUT.PUT_LINE('username: ' || x || ', password: ' || y);
END;