【发布时间】:2012-03-25 07:48:17
【问题描述】:
这是我写的程序:
set serveroutput on;
declare
b empl.name1%type;
r varchar; --can i change this to r empl.designation%type; ?
begin
r:=&designation; --getting input for the designation
dbms_output.put_line('hello'); --random output to check for errors
select name1 into b from empl where designation=r; --i want all the names from the table
dbms_output.put_line('name'||b); --employee where designation is as entered
dbms_output.put_line(' closed'); --by user,should i loop this statement?
end;
当我输入名称为“a”(已在表中输入)时,我收到一个错误
identifier 'a' is not declared。这意味着什么?
选择语句一次占用一行吗?所以如果我循环它会得到所有的行吗?或者我应该使用光标?
为什么 SQL Developer 不接受%rowtype?
我把我的程序改成了这样:
set serveroutput on;
declare
cursor cempl is select name1,designation from empl;
b empl.name1%type;
des empl.designation%type;
r empl.designation%type;
begin
r:='meow';
dbms_output.put_line('hello');
open cempl;
if cempl%ISOPEN then
loop
fetch cempl into b,des;
if des=r then
dbms_output.put_line('name'||b);
end if;
exit when cempl%notfound;
end loop;
close cempl;
dbms_output.put_line(' closed');
end if;
end;
每当我收到r:=&r 之类的输入并想象我输入“a”时,它都会显示
必须声明标识符“a”,但它是表中的值!为什么要声明它,但如果它在上面的程序中给出,它不会给出错误。相反,它重复最后一行两次!
【问题讨论】: