服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > 数据库技术 > Oracle技术 > Oracle开发 > 查看文档

临时表在特定的条件下同样可以灵活易用

【赛迪网-it技术报道】本文介绍了一个四用户同步更新的存储过程实例,通过这个实例的学习,你可以发现临时表在某种条件下也可以是灵活易用的,在数据量小的时候,它并不会显现出临时表速度不行的问题。

set quoted_identifier on 
go
set ansi_nulls on 
go
/*
name:游戏中四人数据同时更新
designed by :whbo
designed at :2005-10-12
modified by :
modified at :
memo:
*/

alter   proc [prmoney_updatecash2]
@chvmodename varchar(16),
@chvsourcename varchar(64),
@chvremark varchar(128),
@intuserid1 int,
@intuserid2 int,
@intuserid3 int,
@intuserid4 int,
@intwantedamount1 int,
@intwantedamount2 int,
@intwantedamount3 int,
@intwantedamount4 int,
@chvipaddress1 varchar(15),
@chvipaddress2 varchar(15),
@chvipaddress3 varchar(15),
@chvipaddress4 varchar(15),
@inylog tinyint
as
set nocount on 
set xact_abort on
declare @intcashamount1 int,@intcashamount2 int,@intcashamount3 int,@intcashamount4 int
declare @frate float,@ftemp float
declare @bneedrecalc bit  --0:不用重算 ;1:需要重算
set @frate=1.0
set @ftemp=1.0
set @bneedrecalc=0
declare @ftemp1 float,@ftemp2 float,@ftemp3 float,@ftemp4 float

--这里要注意,更新用户现金取数据库中的数据,跟游戏服务器能否保持一致
--取得用户现金
select @intcashamount1=[amount] from [dbo].[money] where [userid]=@intuserid1
select @intcashamount2=[amount] from [dbo].[money] where [userid]=@intuserid2
select @intcashamount3=[amount] from [dbo].[money] where [userid]=@intuserid3
select @intcashamount4=[amount] from [dbo].[money] where [userid]=@intuserid4

create table #temp1(ttemp float)

if @intcashamount1+@intwantedamount1<0 
 begin
  set @ftemp=-@intcashamount1/@intwantedamount1
  insert into #temp1 values(@ftemp)
 end


if @intcashamount2+@intwantedamount2<0
 begin
  set @ftemp=-@intcashamount2/@intwantedamount2
  insert into #temp1 values(@ftemp)
 end

if @intcashamount3+@intwantedamount3<0
 begin
  set @ftemp=-@intcashamount3/@intwantedamount3
  insert into #temp1 values(@ftemp)
 end

if @intcashamount4+@intwantedamount4<0
 begin
  set @ftemp=-@intcashamount4/@intwantedamount4
  insert into #temp1 values(@ftemp)
 end

set @ftemp=(select min(@ftemp) from #temp)
drop table #temp1

if @ftemp<@frate
begin
 set @frate=@ftemp
 set @bneedrecalc=1
end

if @bneedrecalc=1 
begin
 set @intwantedamount1=@intwantedamount1*@frate
 set @intwantedamount2=@intwantedamount2*@frate
 set @intwantedamount3=@intwantedamount3*@frate
 set @intwantedamount4=@intwantedamount4*@frate
end

begin tran
exec [prmoney_updatecash]
 @chvmodename,   -- 通过什么方式,如'web'、'gameserver'等
 @chvsourcename,  -- 方式的源,如'金币麻将服务器'、'虚拟股市'等
 @chvremark,  -- 其它信息 注释.
 @intuserid1,    -- 用户id
 0, -- 相关的用户id
 @intwantedamount1,   -- 希望更新的数量(>0 加金, <0 扣金)
 0,    -- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)
 @chvipaddress1,  -- ip地址
 0, -- 机器码
 1    -- 是否做log,如果>0,则表示做log,否则不做log

exec [prmoney_updatecash]
 @chvmodename,   -- 通过什么方式,如'web'、'gameserver'等
 @chvsourcename,  -- 方式的源,如'金币麻将服务器'、'虚拟股市'等
 @chvremark,  -- 其它信息 注释.
 @intuserid2,    -- 用户id
 0, -- 相关的用户id
 @intwantedamount2,   -- 希望更新的数量(>0 加金, <0 扣金)
 0,    -- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)
 @chvipaddress2,  -- ip地址
 0, -- 机器码
 1    -- 是否做log,如果>0,则表示做log,否则不做log

exec [prmoney_updatecash]
 @chvmodename,   -- 通过什么方式,如'web'、'gameserver'等
 @chvsourcename,  -- 方式的源,如'金币麻将服务器'、'虚拟股市'等
 @chvremark,  -- 其它信息 注释.
 @intuserid3,    -- 用户id
 0, -- 相关的用户id
 @intwantedamount3,   -- 希望更新的数量(>0 加金, <0 扣金)
 0,    -- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)
 @chvipaddress3,  -- ip地址
 0, -- 机器码
 1    -- 是否做log,如果>0,则表示做log,否则不做log
exec [prmoney_updatecash]
 @chvmodename,   -- 通过什么方式,如'web'、'gameserver'等
 @chvsourcename,  -- 方式的源,如'金币麻将服务器'、'虚拟股市'等
 @chvremark,  -- 其它信息 注释.
 @intuserid4,    -- 用户id
 0, -- 相关的用户id
 @intwantedamount4,   -- 希望更新的数量(>0 加金, <0 扣金)
 0,    -- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)
 @chvipaddress4,  -- ip地址
 0, -- 机器码
 1    -- 是否做log,如果>0,则表示做log,否则不做log
commit tran
return 1


go
set quoted_identifier off 
go
set ansi_nulls on 
go

扫描关注微信公众号