title: Using a user defined function inside a procedure with a cursor on oracle
body: <p>I'm trying to insert a function that defines a value(salary) into a procedure. that value needs to be inserted into a column in a table(employees).</p>
  
  <p>All the other values that are going to be inserted into the table(employees) are being defined by a cursor(in the procedure) that is extracting data from another table, however the last value(salary) is not on the cursor, but is defined by a function I created instead. How could I add it into my procedure so that the data from my cursor is put into their respective columns and then the function creates the data for the last column of the table?</p>
  
  <p>My procedure is</p>
  
  <pre><code>create or replace 
  PROCEDURE migratestuff
  IS
  CURSOR names_cursor
    IS
      select substr(staff.name, 0, instr(staff.name, ' ') - 1) as firstname,
            substr(staff.name, instr(staff.name, ' ')         + 1) as lastname,
        lower(concat(substr(staff.name, 0,1), substr(staff.name, instr(staff.name, ' ')         + 1)||'@mail.com')) as emails,
        date_created
      from staff;
  employee_rec names_cursor%rowtype;
  counter number := 1;
  BEGIN
    FOR employee_rec IN names_cursor
    LOOP
      INSERT INTO employee
        (fname, lname,Email,emp_ID,hire_date,salary
        ) VALUES
        (employee_rec.firstname, employee_rec.lastname,employee_rec.Emails,counter,
         employee_rec.Date_created,SALARYFUNCTIONRESULTHERE
        );
   commit;   
   counter := counter +1;
    END LOOP;
  end;
  </code></pre>
  
  <p>My function if it helps(This is the function that will give the value salary needs in the insert statement):</p>
  
  <pre><code>CREATE OR REPLACE 
  FUNCTION salary_function(
        in_date IN DATE)
      RETURN NUMBER
    IS
      salary_out NUMBER(5);
    BEGIN
      IF to_char(in_date, 'YYYY') = '2013' THEN
        salary_out               :=7000;
      ELSE
        IF to_char(in_date, 'YYYY') = '2014' THEN
          salary_out               := 6000;
        ELSE
          IF to_char(in_date, 'YYYY') = '2015' THEN
            salary_out               := 5000;
          END IF;
        END IF;
      END IF;
      RETURN salary_out;
    END;
  </code></pre>
  
  <p>Any ideas?</p>