Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to execute a function and return the result into a bind variable

kiran1pudiApr 7 2011 — edited Apr 7 2011
Hi,

I am trying to calculate the sum of salaries of all persons with a particular JOB_ID using a function TOTAL_INCOME(v_job_id).

create or replace function total_income
+(v_job_id IN varchar2)+
RETURN number IS
v_total number(6);

cursor get_sal is
select salary from employees
where job_id = v_job_id;
BEGIN
v_total := 0;
for emp in get_sal
loop
v_total := v_total emp.salary;+
end loop;

dbms_output.put_line('Total salary of '||v_job_id||' is: '|| v_total);
return v_total;
END;

Now I woud like to execute this function and assign the returned value into a bind variable test_sal

variable test_sal number(6)
SELECT total_income('AD_VP') into :test_sal FROM DUAL;
dbms_output.put_line('Total Sal:'||:test_sal);

This is returning the below errors:

SELECT total_income('AD_VP') into :test_sal FROM DUAL
*+
Error at line 0
ORA-01036: illegal variable name/number

dbms_output.put_line('Total Sal:'||:test_sal);
Error at line 3
ORA-00900: invalid SQL statement

Could someone help me what could be the problem?? Thanks for your time...
This post has been answered by Peter Gjelstrup on Apr 7 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2011
Added on Apr 7 2011
4 comments
2,095 views