[英]Error user input PLS-00201: identifier 'ISS' must be declared
Why do I get this error? 为什么会出现此错误? If the variable declaration is the same type as the column shouldn't this work.
如果变量声明与列的类型相同,则不起作用。 The nursing_unit_id is a varchar2(10).
Nurse_unit_id是varchar2(10)。 It worked like this for me when the ID was a NUMBER;
当ID为NUMBER时,它对我来说是这样的;
Error I get: Error report - ORA-06550: line 13, column 13: PLS-00201: identifier 'ISS' must be declared 我得到的错误:错误报告-ORA-06550:第13行,第13列:PLS-00201:必须声明标识符“ ISS”
SET SERVEROUTPUT ON;
DECLARE
v_unit ADMISSIONS.NURSING_UNIT_ID%TYPE := &v_unit;
v_admissions ADMISSIONS%ROWTYPE;
CURSOR c_admissions IS
SELECT *
INTO v_admissions
FROM ADMISSIONS
WHERE NURSING_UNIT_ID = v_unit;
BEGIN
FOR r_admissions IN c_admissions
LOOP
DBMS_OUTPUT.PUT_LINE(r_admissions );
END LOOP;
END;
If nursing_unit_id
is varchar2(10)
and you've defined the substitution variable &v_unit
as ISS
, then you have to enclose the reference to the substitution variable in quotes, to make it a string: 如果
nursing_unit_id
为varchar2(10)
并且您已将替换变量&v_unit
定义为ISS
,则必须将对替换变量的引用括在引号中,以使其成为字符串:
v_unit ADMISSIONS.NURSING_UNIT_ID%TYPE := '&v_unit';
If you run your code in SQL*Plus or SQL Developer with set verify on
, you'll see the before and after values for that substitution, which would show it it trying to to do: 如果您在SQL * Plus或SQL Developer中运行了带有
set verify on
的代码, set verify on
看到该替换之前和之后的值,这将表明它试图执行的操作:
v_unit ADMISSIONS.NURSING_UNIT_ID%TYPE := ISS;
instead of what you'd get with it quoted: 而不是引用它:
v_unit ADMISSIONS.NURSING_UNIT_ID%TYPE := 'ISS';
You will still get other errors; 您仍然会遇到其他错误; the next one is:
下一个是:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
PLS-00306:调用“ PUT_LINE”时参数的数量或类型错误
You've defined v_admissions
as a row type, which means it's a record. 您已将
v_admissions
定义为行类型,这意味着它是一条记录。 You can't write a whole record out in one go with dbms_output
, you have to refer to each field separately, eg (using your amended code, where `r_admissions is also implicitly of that same row type): 您不能使用
dbms_output
一次性写出完整的记录,而必须分别引用每个字段,例如(使用修改后的代码,其中`r_admissions也隐含相同的行类型):
DBMS_OUTPUT.PUT_LINE(r_admissions.nursing_unit_id);
Having an into
clause in the cursor definition isn't useful; 在游标定义中有一个
into
子句是没有用的。 it isn't actually populated, so you can remove that clause and the v_admissions
variable declaration. 它实际上并未填充,因此您可以删除该子句和
v_admissions
变量声明。 You don't really need the v_unit
local variable either, you can use the substitution variable directly; 您实际上也不需要
v_unit
局部变量,可以直接使用替换变量。 and there are various cursor forms you can use, such as: 并且可以使用多种游标形式,例如:
SET SERVEROUTPUT ON;
BEGIN
FOR r_admissions IN (
SELECT *
FROM ADMISSIONS
WHERE NURSING_UNIT_ID = '&v_unit'
)
LOOP
DBMS_OUTPUT.PUT_LINE(r_admissions.nursing_unit_id);
-- and anything else you want to do with that row's data
END LOOP;
END;
/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.