plsql - copy data after comparing a specific value -
i want make procedure in parameters. more specific, have tables folowing table1
|col1 | col2 | col3 | col4 | col5 | col6| ---------------------------------------- |600 | 140 | 2 | 10 | 1600 | 1 | ---------------------------------------- |600 | 140 | 2 | 20 | 1200 | 4 | ---------------------------------------- |600 | 140 | 2 | 15 | 1100 | 3 | ---------------------------------------- |600 | 140 | 2 | 35 | 1700 | 2 | ---------------------------------------- |600 | 140 | 3 | 10 | 1300 | 6 | ---------------------------------------- |600 | 140 | 3 | 15 | 1100 | 5 | ----------------------------------------
for same col1 , col2/col3 , check select different values col4 instance col1=600 , col2=140/col3=2 , col2=140/col3=3 return 20 , 35
and insert in table table1 rows 600 , 140 , 3, 20 , 1200 , 7 (seq number) 600 , 140 , 3, 35 , 1700 , 8 (seq number)
but don't know how can insert statement :(
procedure copy_columns ( p_col1 in a.col1%type, p_from_col2 in b.col2%type, p_from_col3 in b.col3%type, p_to_col2 in b.col2%type, p_to_col3 in b.col3%type, p_flg1 in varchar2, p_flg2 in varchar2, p_flg3 in varchar2, p_flg4 in varchar2, p_flg5 in varchar2 ) cursor c1 select * col1 = p_col1; cursor c2 select * b col1 = p_col1 , col2 = p_col2 , col3 = p_col3 ; begin if p_flg1='n' or p_flg2='n' or p_flg3='n' or p_flg4 ='n' or p_flg5 = 'n' goto label; --do nothing end if; if p_flg1 = 'y' select col4 table1 col1 = p_col1 , col2 = p_from_col2 , col3 = p_from_col3 minus select col4 table1 col1 = p_col1 , col2 = p_to_col2 , col3 = p_to_col3 -- how insert ? end if; if p_flg2 = 'y' select col4 table2 col1 = p_col1 , col2 = p_from_col2 , col3 = p_from_col3 minus select col4 table2 col1 = p_col1 , col2 = p_to_col2 , col3 = p_to_col3 end if; -- .......... <<label>> end;
could me please ? thank you
if i'm not wrong, trying values 1 table , trying insert them table. then, way.
insert yourtable(col1,col2,coln) select col1,col2,coln anothertable;
update
after reading recent comment, seems should use merge. not require use cursor in case.
merge destination d using (select col1, col2 source [condition check]) s on (d.id = s.id) when not matched insert (d.col3, d.col4) values (s.col3, s.col4);
Comments
Post a Comment