Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > update entire column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-03, 20:07
milindoke milindoke is offline
Registered User
 
Join Date: Apr 2003
Location: Atlanta
Posts: 8
update entire column

is it possible in Oracle 9i to update an entire column with a collection variable. eg
in my stored prc i have a pl/sql table "mytab" which has one column "mysal". i do a bulk collect into this table for all the records from the employee table. i process the data and have made the changes to the salary in mytab. now i need to bulk update the entire column salary of employee table with mysal of mytab.
just like bulk collect, does Oracle provide for any way of doing a bulk update
Reply With Quote
  #2 (permalink)  
Old 12-03-03, 10:44
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
Re: update entire column

Quote:
Originally posted by milindoke
is it possible in Oracle 9i to update an entire column with a collection variable. eg
in my stored prc i have a pl/sql table "mytab" which has one column "mysal". i do a bulk collect into this table for all the records from the employee table. i process the data and have made the changes to the salary in mytab. now i need to bulk update the entire column salary of employee table with mysal of mytab.
just like bulk collect, does Oracle provide for any way of doing a bulk update

Yes, there is FORALL:

Code:
declare type num_tab is table of number index by binary_integer; empno_tab num_tab; sal_tab num_tab; begin select empno, sal bulk collect into empno_tab, sal_tab from emp; for i in 1..empno_tab.COUNT loop sal_tab(i) := sal_tab(i) + 10000; end loop; forall i in 1..empno_tab.COUNT update emp set sal = sal_tab(i) where empno = empno_tab(i); end; /

This does of course require that you saved the PK values into a table as well as the salaries!
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
  #3 (permalink)  
Old 12-04-03, 16:39
milindoke milindoke is offline
Registered User
 
Join Date: Apr 2003
Location: Atlanta
Posts: 8
what if i skip the "WHERE" caluse of the update. actually i am in a situation where i do not have PK. so i was expecting a column overlap sortof thing. i might be sounding absurd but cant help it. to explain a bit further consider that i have the employee table sorted on emp_id and when the sal_tab is loaded i sort on emp_id. since both are sorted on emp_id, i want to actually replace the entire column salary with this sal_tab.
Reply With Quote
  #4 (permalink)  
Old 12-04-03, 18:47
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 4,874
This is not a good way to do things, but it could be done like this:

Code:
declare cursor c is select sal from emp order by empno for update of sal; i integer :=0; ... begin for r in c loop i := i+1; update emp set sal = saltab(i) where current of c; end loop; end; /

There is no way to do that in one statement, unless you have the table of PK values.
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On