cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to update data table column values ​​from a certain result value

ximen
Participant
0 Kudos
1,223

How to update data table column values ​​from a certain result value, Use the value of table A to update the value of the cloumn_name column of the tble_name table table A :

tble_name  cloumn_name              UUID_name           ID_value          upnew_value
contacts       city                     ID                1                kitchener
contacts        state                   ID                2                 tx
contacts         fax                     ID                2                 5105551309

Need to be converted to a dynamic cursor to fetch the value

exp:

update    a.table_name set a.clounm_nname=a.n_value where  a.uuid_name=a.id_value

update       contacts      set   city=kitchener                      where  id=1

thanks

Accepted Solutions (1)

Accepted Solutions (1)

ximen
Participant
0 Kudos
    begin
  declare ntable_name char(60);
  declare ncloumn_name char(60);
  declare nuuid_name char(60);
  declare nID_value integer;
  declare nupnew_value char(60);
  declare @sqlstr long varchar;
  declare err_notfound exception for sqlstate value '02000';
  declare update_t dynamic scroll cursor for
    select * from A for update;
  open update_t;
  uploop: loop
    fetch next update_t into ntable_name,ncloumn_name,nuuid_name,nID_value,nupnew_value for update;
    if sqlstate = err_notfound then
      leave uploop
    else
      set @sqlstr = 'UPDATE ' || ntable_name || ' '
         || 'set ' || ncloumn_name || ' = ' ||  ''''||  nupnew_value || ''''||  ' where '
         || nuuid_name || ' = ' || nID_value;
      execute immediate with result set on @sqlstr
    -- prepare updatetable from @sqlstr ;
    --  execute updatetable ;
    --DEALLOCATE PREPARE updatetable; 
    --UPDATE table_name SET ncloumn_name = nupnew_value where nuuid_name=nID_value  
    end if
  end loop uploop;
  close update_t
end
VolkerBarth
Contributor
0 Kudos

Hm? I just don't understand...

But if you have answered your question, than it's fine for me...

ximen
Participant

yes i at docx find My answer.So I share my answers here!thanks all

Answers (0)