Oracle Date Caculation

1.查询条件中
      1.Where to_char(date_column,'yyyy') = '2005'
      2.Where trunc(date_column,'y') = to_date('01-jan-2005','dd-mon-yyyy')
后者不仅有更出色的表现,而且占有的资源更少。与使用TRUNC相比,使用TO_CHAR所用的CPU时间与前者相差一个数量级。这是因为TO_CHAR必须把日期转换为一个串,这要使用一个更大的代码路径,并利用当前的所有NLS来完成这个工作。然后必须执行一个串与串的比较。另一方面,TRUNC只需把后5个字节设置为1.然后将两个7字节的二进制数进行比较,就大功告成了。因此,如果只是要截断一个DATE列,你将应该避免使用TO_CHAR。
另外,如果date_column列上有索引,应写成下面的方式才能用到索引。
     3.select count(*) from t
        where date_column>= to_date('01-jan-2005','dd-mon-yyyy')
        and date_column< to_date('01-jan-2006','dd-mon-yyyy');
 
2.使用Oracle DATE类型时:
? 使用NUMTODSINTERVAL内置函数来增加小时、分钟和秒
? 加一个简单的数来增加天
? 使用ADD_MONTHS内置函数来增加月和年
如select sysdate+numtodsinterval(3,'minute') from dual; 增加3分钟
select sysdate+3 from dual;增加3天
select add_months(to_date('2012-01-30 12:12:12','yyyy-mm-dd hh24:mi:ss'),1) from dual;增加1个月。
 
不要使用NUMTOYMINTERVAL函数,得到的日期并不是下一个月的最后一天,而只是下一个月的同一天
如SQL> select to_date('2012-01-30 12:12:12','yyyy-mm-dd hh24:mi:ss')+numtoyminterval(1,'month') from dual;
select to_date('2012-01-30 12:12:12','yyyy-mm-dd hh24:mi:ss')+numtoyminterval(1,'month') from dual
                                                             *
ERROR at line 1:
ORA-01839: date not valid for month specified
下个月同一天是2012-02-30,它并不存在。
 
3.取当月第一天 select trunc(sysdate,'mm') from dual;
  取当年第一天 select trunc(sysdate,'yyyy') from dual;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24260552/viewspace-740636/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24260552/viewspace-740636/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,根据您的要求,我为您提供以下代码实现: 首先,我们需要定义一个测角交会的类,包括前方交会、后方交会、侧方交会、距离交会的方法: ```csharp class Caculation { //前方交会 public static PointF ForwardIntersection(PointF point1, float angle1, PointF point2, float angle2) { float k1 = (float)Math.Tan((90 - angle1) * Math.PI / 180); float b1 = point1.Y - k1 * point1.X; float k2 = (float)Math.Tan((90 - angle2) * Math.PI / 180); float b2 = point2.Y - k2 * point2.X; float x = (b2 - b1) / (k1 - k2); float y = k1 * x + b1; return new PointF(x, y); } //后方交会 public static PointF BackwardIntersection(PointF point1, float angle1, float distance1, PointF point2, float angle2, float distance2) { float k1 = (float)Math.Tan((90 - angle1) * Math.PI / 180); float b1 = point1.Y - k1 * point1.X; float k2 = (float)Math.Tan((90 - angle2) * Math.PI / 180); float b2 = point2.Y - k2 * point2.X; float x = (b2 - b1) / (k1 - k2); float y = k1 * x + b1; float distance3 = (float)Math.Sqrt(Math.Pow(point1.X - x, 2) + Math.Pow(point1.Y - y, 2)); float angle3 = (float)(Math.Atan2(y - point2.Y, x - point2.X) * 180 / Math.PI); if (angle3 < 0) angle3 += 360; return new PointF(x, y); } //侧方交会 public static PointF SideIntersection(PointF point1, float angle1, float distance1, PointF point2, float angle2, float distance2) { float angle3 = (float)(Math.Atan2(point1.Y - point2.Y, point1.X - point2.X) * 180 / Math.PI); if (angle3 < 0) angle3 += 360; float angle4 = (angle3 + angle2) % 360; float x = point2.X + distance2 * (float)Math.Cos(angle4 * Math.PI / 180); float y = point2.Y + distance2 * (float)Math.Sin(angle4 * Math.PI / 180); return new PointF(x, y); } //距离交会 public static PointF DistanceIntersection(PointF point1, float angle1, float distance1, PointF point2, float angle2, float distance2) { float angle3 = (float)(Math.Atan2(point1.Y - point2.Y, point1.X - point2.X) * 180 / Math.PI); if (angle3 < 0) angle3 += 360; float angle4 = (angle3 + angle2) % 360; float x1 = point1.X + distance1 * (float)Math.Cos(angle1 * Math.PI / 180); float y1 = point1.Y + distance1 * (float)Math.Sin(angle1 * Math.PI / 180); float x2 = point2.X + distance2 * (float)Math.Cos(angle4 * Math.PI / 180); float y2 = point2.Y + distance2 * (float)Math.Sin(angle4 * Math.PI / 180); float x = (x1 + x2) / 2; float y = (y1 + y2) / 2; return new PointF(x, y); } } ``` 接下来,我们可以在控制台应用程序中使用这些方法: ```csharp class Program { static void Main(string[] args) { PointF point1 = new PointF(100, 100); float angle1 = 30; float distance1 = 50; PointF point2 = new PointF(200, 200); float angle2 = 40; float distance2 = 70; //前方交会 PointF forwardIntersection = Caculation.ForwardIntersection(point1, angle1, point2, angle2); Console.WriteLine("前方交会:({0},{1})", forwardIntersection.X, forwardIntersection.Y); //后方交会 PointF backwardIntersection = Caculation.BackwardIntersection(point1, angle1, distance1, point2, angle2, distance2); Console.WriteLine("后方交会:({0},{1})", backwardIntersection.X, backwardIntersection.Y); //侧方交会 PointF sideIntersection = Caculation.SideIntersection(point1, angle1, distance1, point2, angle2, distance2); Console.WriteLine("侧方交会:({0},{1})", sideIntersection.X, sideIntersection.Y); //距离交会 PointF distanceIntersection = Caculation.DistanceIntersection(point1, angle1, distance1, point2, angle2, distance2); Console.WriteLine("距离交会:({0},{1})", distanceIntersection.X, distanceIntersection.Y); Console.ReadKey(); } } ``` 这样就可以实现测角交会定点计算了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值