网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>数据库技术>>Oracle技术>>Oracle开发>查看文档  
  临时表在特定的条件下同样可以灵活易用     
  文章作者:未知  文章来源:赛迪网技术社区  
  查看:71次  录入:管理员--2008-05-16  
 

【赛迪网-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

 
 
上一篇: 用简单的方法获取oracle语句的执行时间    下一篇: 使用_disable_logging即可禁止日志的生成 (1)
  相关文档
ip地址变化后oracle 10g如何才能不受影响 04-15
Oracle 10g数据库的安全性和身份管理 06-03
教你通过任务和管道异步调用存储过程 04-11
oracle数据库管理员经常使用的表和视图 (1) 03-03
oracle数据库各种启动方式的详细介绍 01-25
Oracle平台应用数据库系统的设计与开发 09-29
使用java调用oracle数据库的存储过程实例 08-12
讲解"oracle"下导出某用户所有表的方法 02-02
如何利用oracle的全文索引实现切词功能 02-27
深刻理解Oracle数据库的启动和关闭 01-15
用oracle的功能特性提高应用的执行效率 (1) 03-24
怎样在oracle里用存储过程定期分割表 (1) 01-25
在Oracle 10g中如何获得索引建议 05-13
oracle数据库10g环境下修改vip地址的方法 07-25
教你如何收集Oracle进程中SQL跟踪信息 05-27
Oracle中用LogMiner分析重做及归档日志 04-11
在oracle 10g中建立没有域名的db_link 03-21
用quick slice获取oracle进程的线程状态 07-07
全面讲解归档可用的缓冲大小和数量调整 04-16
利用Oracle管理服务器将数据导入导出 04-11
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
厦门(总部):13616026886 福州:0591-87655121
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息