Sql Server與Oracle儲存過程轉換
阿新 • • 發佈:2019-01-03
在sql 向oracle 遷移過程中,最頭疼的也許就是儲存過程的轉換了,之前利用sql/developer 將sql 資料遷移到oracle 裡面去了,但是對於儲存過程來說,還需要進行大量的後續更改,下面就介紹一個sql 中的一個update 語句是如何轉向 oracle的
例子:
Sql:
declare @locatidnext char(11),
@sphwcount int, @goodsidnext char(11),
@upshl decimal(14,3), @fpsl decimal(14,3)
set @sphwcount = 0
set @upshl = 0.00
set @fpsl = 0.00
set @goodsidnext = ''
set @locatidnext = ''
update #tmppicils set
@upshl = case when goodsid <> @goodsidnext then upshl else @upshl - @fpsl end,
@sphwcount = case when goodsid <> @goodsidnext /*or hw <> @hwnext*/ then 1 else @sphwcount + 1 end,
@fpsl = biandongsl = case when @sphwcount = sphwcount and num>@upshl then @upshl
when @sphwcount = sphwcount and num< [email protected] then num
when num > @upshl then @upshl
else num
end,
@goodsidnext = goodsid,
@locatidnext = locatid 對於上面的語句,如何修改成oracle的呢,首先我們要明白上面的邏輯,之前也詢問過一些sql 的相關人員,有人認為這就是一個基本的case when,其實這條語句是一條迴圈update,下面就是轉換成oracle的寫法: open cv_2;
fetch cv_2 into v_count2,goodsid,upshl,sphwcount,num,locatid;
while cv_2%found loop
v_upshl:=case when goodsid<>v_goodsidnext then upshl else v_upshl-v_fpsl end;
v_sphwcount:=case when goodsid<>v_goodsidnext then 1 else v_sphwcount + 1 end;
update tmppicils set biandongsl=case when v_sphwcount = sphwcount and num>v_upshl then v_upshl
when v_sphwcount = sphwcount and num<=v_upshl then num
when num > v_upshl then v_upshl
else num end where id=v_count2 returning biandongsl into v_fpsl ;
v_goodsidnext:= goodsid;
v_locatidnext:= locatid;
--v_count2:=v_count2+1;
fetch cv_2 into v_count2,goodsid,upshl,sphwcount,num,locatid;
end loop;
close cv_2;
@sphwcount int, @goodsidnext char(11),
@upshl decimal(14,3), @fpsl decimal(14,3)
set @sphwcount = 0
set @upshl = 0.00
set @fpsl = 0.00
set @goodsidnext = ''
set @locatidnext = ''
update #tmppicils set
@upshl = case when goodsid <> @goodsidnext then upshl else @upshl - @fpsl end,
@sphwcount = case when goodsid <> @goodsidnext /*or hw <> @hwnext*/ then 1 else @sphwcount + 1 end,
@fpsl = biandongsl = case when @sphwcount = sphwcount and num>@upshl then @upshl
when @sphwcount = sphwcount and num<
when num > @upshl then @upshl
else num
end,
@goodsidnext = goodsid,
@locatidnext = locatid 對於上面的語句,如何修改成oracle的呢,首先我們要明白上面的邏輯,之前也詢問過一些sql 的相關人員,有人認為這就是一個基本的case when,其實這條語句是一條迴圈update,下面就是轉換成oracle的寫法: open cv_2;
fetch cv_2 into v_count2,goodsid,upshl,sphwcount,num,locatid;
while cv_2%found loop
v_upshl:=case when goodsid<>v_goodsidnext then upshl else v_upshl-v_fpsl end;
v_sphwcount:=case when goodsid<>v_goodsidnext then 1 else v_sphwcount + 1 end;
update tmppicils set biandongsl=case when v_sphwcount = sphwcount and num>v_upshl then v_upshl
when v_sphwcount = sphwcount and num<=v_upshl then num
when num > v_upshl then v_upshl
else num end where id=v_count2 returning biandongsl into v_fpsl ;
v_goodsidnext:= goodsid;
v_locatidnext:= locatid;
--v_count2:=v_count2+1;
fetch cv_2 into v_count2,goodsid,upshl,sphwcount,num,locatid;
end loop;
close cv_2;