在 Oracle SQL 函数中声明多个变量
Declare multiple variables in an Oracle SQL function
我希望在我的 SQL 块中使用多个局部变量,但我总是会遇到一些错误。我只需要return
的sum of salary
。有什么想法吗?
function Foo(projekt varchar2)
return number
is sumSalary number;
cursor kurzor is (
select *
from (hr.employees inner join hr.workon using (employee_id))
inner join hr.proj using (projno));
oneLine kurzor%ROWTYPE;
begin
sumSalary := 0;
for oneLine in kurzor
loop
if oneLine.pname = projekt then
dbms_output.put_line(concat(concat(oneLine.first_name,' '),oneLine.last_name));
sumSalary := sumSalary+ oneLine.salary;
end if;
if oneLine.salary > 7500 then
insert into HighSalary values(oneLine.first_name,oneLine.salary);
end if;
end loop;
exception
when others then
dbms_output.put_line('asd');
end;
我的错误:
Error report: ORA-06550: line 2, column 1: PLS-00201: identifier
'SUMSALARY' must be declared ORA-06550: line 2, column 1: PL/SQL:
Statement ignored ORA-06550: line 3, column 15: PLS-00201: identifier
'KURZOR' must be declared ORA-06550: line 3, column 1: PL/SQL:
Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
function Foo(projekt varchar2)
return number
is sumSalary number; // remove this semicolon
cursor kurzor is (
我希望在我的 SQL 块中使用多个局部变量,但我总是会遇到一些错误。我只需要return
的sum of salary
。有什么想法吗?
function Foo(projekt varchar2)
return number
is sumSalary number;
cursor kurzor is (
select *
from (hr.employees inner join hr.workon using (employee_id))
inner join hr.proj using (projno));
oneLine kurzor%ROWTYPE;
begin
sumSalary := 0;
for oneLine in kurzor
loop
if oneLine.pname = projekt then
dbms_output.put_line(concat(concat(oneLine.first_name,' '),oneLine.last_name));
sumSalary := sumSalary+ oneLine.salary;
end if;
if oneLine.salary > 7500 then
insert into HighSalary values(oneLine.first_name,oneLine.salary);
end if;
end loop;
exception
when others then
dbms_output.put_line('asd');
end;
我的错误:
Error report: ORA-06550: line 2, column 1: PLS-00201: identifier 'SUMSALARY' must be declared ORA-06550: line 2, column 1: PL/SQL: Statement ignored ORA-06550: line 3, column 15: PLS-00201: identifier 'KURZOR' must be declared ORA-06550: line 3, column 1: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
function Foo(projekt varchar2)
return number
is sumSalary number; // remove this semicolon
cursor kurzor is (