English 中文(简体)
如何比较PL/SQL中的时间长度
原标题:How to compare timestamp in PL/SQL

Ive this statement:

create table times (time_in timestamp, time_out timestamp);
insert into times values(to_timestamp( 02-MAY-11 07.57.00.000000 AM ), to_timestamp( 02-MAY-11 07.30.00.000000 PM ));
select extract(hour from(time_out-time_in))|| : ||extract(minute from(time_out-time_in)) from times;

EXTRACT(HOURFROM(TIME_OUT-TIME_IN))|| : ||EXTRACT(MINUTEFROM(TIME_OUT-TIME_IN))   
--------------------------------------------------------------------------------- 
11:33

现在,大麻与上述结果比较。 例如:IF [result] > [8个小时] TheN ...

如何做到这一点?

最佳回答
SELECT *
FROM times
WHERE time_out - time_in > interval  8  hour

在一项PL/SQL程序之外,这样做是为了:

declare
  result interval day to second;
begin

  -- !!! make sure this select returns only one row, or use a cursor !!!
  select time_out - time_in 
     into result
  from times; 

  if (result > interval  8  hour) then
    dbms_output.put_line( greater );
  end if;
end;
/
问题回答

暂无回答




相关问题
Change the date format in kibana

I am working for my internship on the implementation of the ElasticSearch family (ElasticSearch+ Kibana+ logstash). Here is my question: I have a field "@ timestamp" with the following format: 2014-05-...

Quickly getting to YYYY-mm-dd HH:MM:SS in Perl

When writing Perl scripts I frequently find the need to obtain the current time represented as a string formatted as YYYY-mm-dd HH:MM:SS (say 2009-11-29 14:28:29). In doing this I find myself taking ...

Sorting by unknown column type in mysql

So I ve got a users table; storing things like username, email, etc. I then have a user_settings table. Instead of standard columns like timestamp_logged_in, profile_views, etc., I have it organized ...

timestamp date today

Hi guys could you please help me with this. I know it is silly but can t find unswer anywhere: I have a query that shows events from the today time_stamp but I want to include today as well. How do I ...

connection time zone issue with jOra eclipse plugin

I started using the jOra eclipse plugin. The plugin seems pretty robust and I m hoping to stop using SQLDeveloper for 95% of my database needs. Many of our tables have columns of type TIMESTAMP ...

How to get a UNIVERSAL Windows batch file timestamp

I m having trouble generating a timestamp in a Windows batch file, because I get diferent date formats on different Windows versions. My machine: >echo %date% >Tue 11/17/2009 Friends machine: ...

热门标签