Updating a table in pl sql
Firstly: if the subselect was returning multiple values, then the for loop will be overwriting the name on table2 multiple times for some/all records (not clean). Assuming the outcome of the for loop was intended, the original subselect could have been rewritten in some controlled way to return only 1 value for each record...
Secondly: there is no order by clause so this will occur in an unpredictable manner (i.e. simplest contrived way would be (select min(name)...)Long story short: if you can at all avoid it, never ever EVER use any kind of LOOP in a T-SQL statement.
These collections can be used in PL/SQL code as types or as types within Tables.
Nested Table Type Topics include: creating a table with this type, inserting a record with this type and updating a record with this type.
When I try to update only the missing data the non-matched data is also updated but to NULL. The reason some of your rows are getting NULLs updated is due to the subquery.UPDATE Table1 T1 SET T1= (SELECT T2FROM Table2 T2 WHERE T2= T1.id), T1= (SELECT T2FROM Table2 T2 WHERE T2= T1.id) WHERE T1IN (SELECT T2FROM Table2 T2 WHERE T2= T1.id); The full example is here: beef is in having the columns that you want to use as the key in parentheses in the where clause before 'in' and have the select statement with the same column names in parentheses.