如何从Oracle快速选择数据 [英] How to fastly select data from Oracle

查看:58
本文介绍了如何从Oracle快速选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Oracle表:

i have the following Oracle table:

GAMES    
    id_game int
    id_user int
    dt_game DATE

在创建新记录之前,我必须检查同一用户一天插入游戏的次数不超过N次.

Before creating a new record i must check that the same user has not inserted a game more that N times a day.

我实际上是通过这种方式选择今天玩的游戏数量:

I'm actually selecting the number of games played today in this way:

select count(1) as num from GAMES 
where id_user=ID_USER and
to_char(dt_game,'DD/MM/YYYY')=to_char(sysdate,'DD/MM/YYYY')

我不太喜欢它:有更好的方法吗?

I don't like it too much: is there a better way to do it?

先谢谢了 c.

推荐答案

日期转换没有意义,并且会阻止使用该列上的任何索引;您可以使用dt_game > trunc(sysdate)简化该位.

The date conversions are a bit pointless and prevent any index on that column being used; you could simplify that bit with dt_game > trunc(sysdate).

这篇关于如何从Oracle快速选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆