---
title: "Oracle日期时间应用（二）"
author: "Illy"
date: "2011-08-04T15:35:25Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2011-08-04T15:35:25Z"
id: 1140103
url: "https://illy.iteye.com/blog/1140103"
---

1.在表test中有起始日期（start_date）、终止日期（end_date）字段，求终止日期离当前日期的天数，终止日期小于当前日期返回0，否则返回相差天数，SQL如下：
select decode(sign(to_date(max(e.end_date))-max(trunc(sysdate))),1,(to_date(max(e.end_date))-max(trunc(sysdate))),0) from test e