oracle - Insert into a table based on a cursor -



oracle - Insert into a table based on a cursor -

i have below tables:

table1:

| resp_id | description | | 1 | aa | | 2 | aa | | 3 | aa |

table 2:

| org_id | resp_id | date | gid | | 001 | 1 | 08-sep-14 | 112 | | 002 | 1 | 08-sep-14 | 112 | | 003 | 3 | 08-sep-14 | 114 | | 004 | 5 | 08-sep-14 | | | 005 | 5 | 08-sep-14 | | | 006 | 6 | 08-sep-14 | |

my requirement this: need insert gid table2 if resp_id in table2 not found in table1.

hence wrote below script doesn't work:

declare cursor resp_id_cursor select resp_id table1 description '%aa%'; flag number; begin resp_cur in resp_id_cursor select 1 flag table2 a.resp_id = resp_cur.resp_id; if flag != 1 insert table2 (gid) values(115); end if; end loop; end; /

please advice.. thanks!

please seek code,

declare cursor r1 select resp_id table2; gid1 number:= 115; flag number:=0; begin c1 in r1 loop begin dbms_output.put_line('in here'); select count(*) flag table1 a.resp_id = c1.resp_id ; dbms_output.put_line('flag '||flag); dbms_output.put_line( c1.resp_id ); if (flag = 0) dbms_output.put_line('doesnt exist'); update table2 set gid=gid1 resp_id =c1.resp_id ; dbms_output.put_line('update value resp_id '||c1.resp_id ); dbms_output.put_line('gid inserted '||gid1); flag:=0; commit; dbms_output.put_line('commited'); end if; exception when no_data_found dbms_output.put_line('no info found resp_id '||c1.resp_id ); end; gid1:=gid1+1; end loop; end;

oracle plsql cursor

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -