1

I try update salary, but get error:

invalid ROWID

Cause: A ROWID was entered incorrectly. ROWIDs must be entered as formatted hexadecimal strings using only numbers and the characters A through F. A typical ROWID format is '000001F8.0001.0006'.

this is my code

DECLARE 
    CURSOR get_sls(mgr NUMBER, dep VARCHAR2) IS 
      SELECT * 
        FROM emp_n_m
       WHERE emp_n_m.mgr = mgr 
        FOR UPDATE OF emp_n_m.sal ;
BEGIN 
  OPEN get_sls(7902, 'SALES');
  if (get_sls%notfound) then
     dbms_output.put_line('incorrect mgr');
  else
    UPDATE emp_n_m
       SET emp_n_m.sal = emp_n_m.sal + 50
     WHERE CURRENT OF get_sls;  
    COMMIT; 
  end if;
  CLOSE get_sls;
END;
/ 
Nick Krasnov
  • 26,886
  • 6
  • 61
  • 78

2 Answers2

1

this should work:

DECLARE 
    CURSOR get_sls(mgr NUMBER, dep VARCHAR2) IS 
      SELECT * 
        FROM emp_n_m
       WHERE emp_n_m.mgr = mgr 
        FOR UPDATE OF emp_n_m.sal ;
  v_emp get_sls%rowtype;
BEGIN 
  OPEN get_sls(7902, 'SALES');
  FETCH get_sls INTO v_emp;
  if (get_sls%notfound) then
     dbms_output.put_line('incorrect mgr');
  else
    UPDATE emp_n_m
       SET emp_n_m.sal = emp_n_m.sal + 50
     WHERE CURRENT OF get_sls;  
    COMMIT; 
  end if;
  CLOSE get_sls;
END;
/ 
Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102
0

Is the cursor really required in your case? Would it not be efficient to get this done in a DML operation?

All you want to do is to update salary for manager 7902 from dept 'SALES ...

UPDATE emp_n_m SET emp_n_m.sal = emp_n_m.sal + 50 
WHERE emp_n_m.mgr =  7902
AND dept = 'SALES';

COMMIT; 
pahariayogi
  • 1,073
  • 1
  • 7
  • 18