The following function checks to see if a zip code is present in a table called ZIPCODE:
create or replace function zip_does_not_exist(i_zip in zipcode.zip%type)
return boolean
as
v_zip zipcode.zip%type;
begin
select zip into v_zip
from zipcode
where zip = i_zip;
if v_zip is not null then
return false;
else
return true;
end if;
end;
/
The schema for the ZIPCODE table is as follows:

To test this function, I issued the following statement which should return false as the zip code passed as an argument is present in the ZIPCODE table:
select zip_does_not_exist('00914') from dual;
However, I receive this message when trying to run this code:
Error report:
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
This should not be happening, as '00914' is the proper datatype needed as an argument (varchar2(5)). Why am I receiving this message?
booleandata type, while PL/SQL does. You may ask "what good is it in PL/SQL if I can't use it." The answer is "you can use it, but only in other PL/SQL code - not in SQL". If you need to use a value like that in SQL code (and often you do), make the return data typenumberand the return values 0 and 1 (for false and true), orchar(1)with values'F', 'T'or maybe'N', 'Y'.