sql - Update using subquery in plsql block -
if comm null, need update comm
value salary
, 1100
, not getting updated.
my data is:
sal comm 9000 800 2975 800 3000 800 1100 3000 800
my code is:
declare cursor c3 select sal,comm,ename emp deptno=20 update of comm; begin c in c3 loop if c.comm null update emp set comm=(select c.sal emp e e.comm=c.comm ) current of c3; end if; end loop; end;
please give me opinion on this.
this line:
update emp set comm=(select c.sal emp e e.comm=c.comm )
... not work. know c.comm
null, you're trying find record on emp
matching value, , can't use equality test null
. won't work if there more 1 record comm
null
- in case, of possible sal
values use?
you don't need query emp
again @ all; select
pointless, if worked, since can data row you're updating:
update emp set comm = sal current of c3;
you remove if
test changing cursor null
values:
cursor c3 select sal,comm,ename emp deptno=20 , comm null update of comm;
but other answers have pointed out, don't need in pl/sql @ all, simple sql update
suffice.
Comments
Post a Comment