Question

I am trying to create a fucntion that will read in the value of a column, that is either "H", "C" or "N" and return "Hot", "Cold" or "None", but the case statement i have written keeps casuing this error:

Error at line 5: PL/SQL: Statement ignored

Here is my code, i'm not sure what i'm doing wrong, and the error is typically vague.

CREATE OR REPLACE FUNCTION refreshment(
code IN string)
RETURN STRING IS
BEGIN
RETURN(
CASE code
WHEN "H" THEN "Hot"
WHEN "C" THEN "Cold"
WHEN "N" THEN "None"
END
);
END;
Was it helpful?

Solution

First, string is not a valid date type. You need varchar2 instead. Second, strings are delimited by single quotes not double quotes.

It would appear, therefore, that you want

CREATE OR REPLACE FUNCTION refreshment( p_code IN VARCHAR2 )
  RETURN VARCHAR2
IS
BEGIN
  RETURN CASE p_code
           WHEN 'H' THEN 'Hot'
           WHEN 'C' THEN 'Cold'
           WHEN 'N' THEN 'None'
         END;
END;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top