oracle-databaseplsqlpls-00201

PLSQL error PLS-00201: identifier must be declared


I am working on a games users database. I am trying to create a function wich returns the number of users who live in a state (requested when executing the function). So:

CREATE OR REPLACE FUNCTION userNumber(v_state users.state%type)
RETURN number
AS
    result number(10);
    
BEGIN
    SELECT COUNT(*) INTO result
    FROM users
    WHERE users.state= v_state;
    
    RETURN result;
END;
/

And when I try to use it, (for example with the state name FLORIDA) it shows me that error: PLS-00201: identifier 'FLORIDA' must be declared.

declare
    v_state users.state%type:=&state;
    v_result number(10);
    
begin 
    v_result := userNumber(v_state);
    dbms_output.put_line('The users number of the state '|| v_state || ' is ' || v_result);
end;
/

I'd appreciate any help.


Solution

  • "Florida" is a string, so you'll have to enclose substitution variable into single quotes:

    v_state users.state%type := '&state';