on 2020 Feb 16 11:49 AM
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
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes i at docx find My answer.So I share my answers here!thanks all
User | Count |
---|---|
33 | |
21 | |
16 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.