简体   繁体   English

PLS-00201:必须声明标识符“ D”

[英]PLS-00201: identifier 'D' must be declared

Please check my procedure. 请检查我的程序。 I got error when I tried to pass string to procedure. 尝试将字符串传递给过程时出现错误。 It worked fine if I pass number. 如果我通过电话号码,效果很好。

DECLARE 
    x   number(2);
    name    varchar2(333);
    PROCEDURE hello(id IN OUT Number, name in varchar2)
    IS
        i number(2):= 1;
        mName   varchar2(3000):='jjjj';
    BEGIN
        dbms_output.put_line('This line is in procedure'); 
        while i < id
        loop
            mName:= '' || ' ohlla';         
            dbms_output.put_line('Id is ' || i ||  ' name ' || mName );
            i:=i+1;
        end loop;
    END;
BEGIN
    x := &id;
    name:= &somename;   
    hello(x, name);
    dbms_output.put_line('Last line is id= ' || x || ' Finished ' );

END;
/

You are missing quotes in assignment to a string variable; 您在分配给字符串变量时缺少引号; try: 尝试:

name:= '&somename';

This way it will work with numeric IDs and literal names; 这样,它将与数字ID和文字名称一起使用; if you need literal IDs, you need to change the type of variable x and add quotes in the assignment to x too. 如果需要文字ID,则需要更改变量x的类型,并在x的赋值中添加引号。

The preferred solution is to make the change suggested by Aleksej in your code (put quotes around &somename in the assignment). 首选的解决方案是在代码中进行Aleksej建议的更改(在作业中的&somename前后加上引号)。

A workaround, which you may need if you can't change the procedure (for example if you don't own it, or if other procedures may depend on this one and they may break if you make changes - even if the change is to make THIS procedure better) is to pass the string to the procedure WITH QUOTES, like so: 一种变通方法,如果您无法更改该过程(例如,如果您不拥有该过程,或者其他过程可能依赖于此过程,并且如果您进行更改,则它们可能会中断,即使更改是为了解决该问题,则可能需要)。使此过程更好)是将字符串传递给WITH QUOTES过程,如下所示:

SQL> enter value for &somename: 'mary' SQL>输入&somename的值:“ mary”

Substitution variables are substituted verbatim, so you need the quotes for a varchar2 (in one and only one place, either in the code or in the assignment to the substitution variable &somename, outside the procedure). 替换变量逐字替换,因此您需要在varchar2中加引号(在程序外部,或者在代码中或在替换变量&somename的赋值中只能在一个位置)。

Is this an actual procedure you wrote or are you using it just as an example? 这是您编写的实际过程,还是仅用作示例? I ask because I didn't see where you use the input variable "name" in the inner procedure. 我问是因为在内部过程中没有看到您在何处使用输入变量“ name”。

And, to clarify the error message: If you pass mary (with no quotes), when compilation gets to the offending assignment, the compiler assumes mary is the name of another variable (since is not a character literal); 并且,为了澄清错误消息:如果您传递mary(不带引号),则当编译到达有问题的赋值时,编译器会假定mary是另一个变量的名称(因为它不是字符文字); but it knows of no variable named mary, so it raises the exception you saw. 但它不知道名为mary的变量,因此会引发您所看到的异常。 The compiler doesn't guess correctly at what the actual error is (missing quotes). 编译器无法正确猜测实际错误(缺少引号)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM