-- frednum.sql

DECLARE
   lname person.lastname%TYPE;
   fname person.firstname%TYPE;
   namecount NUMBER;
BEGIN
   fname := 'Fred';
   lname := 'Dobbs';

   /**** Skip this temporarily and hard-code namecount... 
   SELECT count(id) + 1
     INTO namecount
     FROM person
    WHERE firstname = fname AND lastname LIKE lname || '%';
   *****/
   namecount := 4;

   IF namecount > 1 THEN
      --Explicit conversion of number to a Roman Numeral character
      lname := lname || ' ' || LTRIM(TO_CHAR(namecount, 'RN')); 
   END IF;

   INSERT INTO person (id, firstname, lastname)
          VALUES (person_id_seq.NEXTVAL, fname, lname);
END;
/
