Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
qamarzaman
Starting Member
1 Post |
Posted - 2009-06-24 : 04:20:01
|
| Hi,Im trying to update a field in a table through a cursor, and selecting joined tables in the cursor. I want to assign new order_id from the sequence (.nextval),or assign the current id in the sequence (.currval) depending on a column in the sequence. If the value of my_cur.no_of_sites = 1, then assign (.nextval)elsifmy_cur.no_of_sites > 1 AND the value in a variable is the same aslast fetched into it then use (.currval)else(.nextval)------------------im pasting the PL CODE im trying to run. Can someone please have a look at it and tell me where am i going wrong.Many Thanks----------------------------------drop sequence seq_order_id;Col Maxid New_Value _maxidSelect Max(order_Id + 1) Maxid From sales_order;Create Sequence seq_order_Id Start With &&_maxid Increment By 1;declarecursor order_cur ISselect pi.*, nosv.*from ph2_item pi inner joinno_of_sites_view nosvon pi.customer_id = nosv.idorder by pi.customer_id, pi.ship_datefor update of pi.order_id;custid ph2_item.customer_id%type;sdate ph2_item.ship_date%type;BEGIN--select my_cur.customer_id into custid;--select my_cur.sgip_date into sdate;for my_cur in order_cur loopif my_cur.no_of_sites = 1thenupdate ph2_item piSETpi.order_id = seq_order_id.nextvalwhere pi.order_id = my_cur.order_id;elsif my_cur.no_of_sites > 1 AND my_cur.customer_id = custid AND my_cur.ship_date = sdatethenupdate ph2_item piSETpi.order_id = seq_order_id.currval;--where pi.customer_id = my_cur.customer_idelsif my_cur.no_of_sites >1 thenpi.order_id = seq_order_id.nextval;end if;select my_cur.customer_id into custid;select my_cur.sgip_date into sdate;--commit;end loop;END;/ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-24 : 06:28:53
|
This is a Microsoft SQL Server forum.You might want to look at www.dbforums.com for PL-SQL forum. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|