question

sqlnewb avatar image
sqlnewb asked

Pass parameters

I am trying to calculate the age of a person by passing in their first and last name as parameters in a function. The function compiles but when i run the below query It returns all the persons names in the table and assigns them all the age of the Employee I passed in the parameter. I just want the person I pass in the parameter to show when I run the query. Any ideas why this is occuring? I am using Oracle create or replace function CALC_AGE (p_first in employees.first_name%type, p_last in employees.last_name%type) return NUMBER is v_empdate employees.dob%type; begin SELECT dob into v_empdate FROM employees WHERE first_name = p_first and last_name = p_last; return( Floor(( TRUNC(SYSDATE) - TRUNC(v_empdate) )/365.25)); end CALC_AGE; SELECT first_name||' '||last_name as Employee, Calc_Age('JAMES', 'MURRAY') as Age, dob as Birthday ` FROM employees
oracleparametersfunctionsoracle-sql-developer
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Daniel Ross avatar image
Daniel Ross answered
change your select statement to select first_name|| ' '|| last_name as Employee, Calc_Age(first_name,last_name) as age, dob as Birthday from employees where first_name='JAMES' and last_name='MURRAY'
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks that was the probelm :)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.