這是我寫的程序:標識符必須聲明? PL/SQL錯誤
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
。那是什麼意思? select語句一次只讀取一行嗎?所以如果我循環它會得到所有的行?或者我應該使用光標? 爲什麼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」必須聲明,但其在表中的值!爲什麼要聲明,但如果它在上面的程序中給出,它不會給出錯誤。相反,它會重複最後一行兩次!
謝謝你,是的,我注意到它,並改變了它;) – LoveMeow 2012-03-25 08:56:51