vinoth kumar
vinoth kumar

Reputation: 9

Unable to pass varchar datatype as input parameter in my SQL function

Unable to pass varchar2 datatype in my function. Below is my code:

create 
or replace function f1(i varchar2) return varchar is j varchar2(10);
begin
   select
      last_name into j 
   from
      employees 
   where
      first_name = 'I';
return j;
end
;
/

Select f1('Steven') from dual;

It is showing null value instead of returning the Name.

Upvotes: 0

Views: 56

Answers (1)

Acroyear
Acroyear

Reputation: 1460

You need to reference your parameter without quotes in your where clause, not as 'I'.

create or replace function f1(i varchar2)
return varchar
is
j varchar2(10);
begin
select last_name
into j
from per_all_people_f
where first_name=i;
return j;
end;

Upvotes: 1

Related Questions