Home Database Mysql Tutorial pl/sql对采用数字格式的日期进行日期的转换

pl/sql对采用数字格式的日期进行日期的转换

Jun 07, 2016 pm 02:55 PM
sql number date Format Reality Convert conduct use

现实中会有一种计算方法将时间计算为一个浮点数的形式来保存,这个时候就需要将其转为为可以看得懂的 日期格式 PL/SQL 数字化日期 --将用小数形式表示的 日期时间 转化为 天-小时-分钟-秒 的形式function fmt_time (p_days in number) return varchar2as l_da

现实中会有一种计算方法将时间计算为一个浮点数的形式来保存,这个时候就需要将其转为为可以看得懂的 日期格式 PL/SQL 数字化日期
--将用小数形式表示的 日期时间  转化为 天-小时-分钟-秒 的形式
function fmt_time (p_days in number) return varchar2
as
  l_days            number;
  l_hours           number;
  l_minutes         number;
  l_seconds         number;
  l_sign            varchar2(1);
  l_returnvalue     string_util_pkg.t_max_pl_varchar2;
begin

  /*

  Purpose:    get time formatted as days, hours, minutes, seconds

  Remarks:

  Who     Date        Description
  ------  ----------  -------------------------------------
  MBR     18.12.2006  Created

  */
  --通过传入的 日期获得相应的 各个单位数据
  --整数部分为 天
  l_days := nvl(trunc(p_days),0);
  --小数部分 *24 得到小时
  l_hours := nvl(((p_days - l_days) * 24), 0);
  --获得的小时 数据的小数部分 *60 为分钟
  l_minutes := nvl(((l_hours - trunc(l_hours))) * 60, 0);
  --同样的 将获得的 分钟的小数部分*60 为秒
  l_seconds := nvl(((l_minutes - trunc(l_minutes))) * 60, 0);
  --判断日期正负 符号
  if p_days < 0 then
    l_sign:='minus ';
  else
    l_sign:='';
  end if;
  --将得到的数据 进行格式化  绝对值是为了进行必要的 去除正负号判定
  --获得天的绝对值
  l_days:=abs(l_days);
  --获得小时的绝对值 同时获得其整数部分
  l_hours:=trunc(abs(l_hours));
  --去取分钟的绝对值 然后四舍五入
  l_minutes:=round(abs(l_minutes));
  --去取秒的绝对值 然后四舍五入
  l_seconds:=round(abs(l_seconds));
  --如果分钟 为60  为什么会出现这种情况呢? 这是因为有了四舍五入和小数 不精确所致
  if l_minutes = 60 then
    --则 让小时+1 同时分钟置空
    l_hours:=l_hours + 1;
    l_minutes:=0;
  end if;
  --将得到的结果 进行格式化输出
  --采用 天-》小时-》分钟的判断顺序 是为了 能够决定那个 字段木有值
  if l_days > 0 then
    l_returnvalue:=string_util_pkg.get_str('%1 days, %2 hours, %3 minutes', l_days, l_hours, l_minutes);
  elsif l_hours > 0 then
    l_returnvalue:=string_util_pkg.get_str('%1 hours, %2 minutes, %3 seconds', l_hours, l_minutes, l_seconds);
  elsif l_minutes > 0 then
    l_returnvalue:=string_util_pkg.get_str('%1 minutes, %2 seconds', l_minutes, l_seconds);
  else
    l_returnvalue:=string_util_pkg.get_str('%1 seconds', l_seconds);
  end if;
  --加上 符号
  l_returnvalue:=l_sign || l_returnvalue;

  return l_returnvalue;

end fmt_time;
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo Mar 30, 2024 pm 07:26 PM

1. First open the mobile web browser, search for the Weibo web version, and click the avatar button in the upper left corner after entering. 2. Then click Settings in the upper right corner. 3. Click the version switching option in settings. 4. Then select the color version option in the version switch. 5. Click Search to enter the search page. 6. After entering the keywords, click Find People. 7. When the search completion interface appears, click Filter. 8. Finally, enter the specific date in the release time column and click Filter.

What is the difference between HQL and SQL in Hibernate framework? What is the difference between HQL and SQL in Hibernate framework? Apr 17, 2024 pm 02:57 PM

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Practical tips for converting full-width English letters into half-width form Practical tips for converting full-width English letters into half-width form Mar 26, 2024 am 09:54 AM

Practical tips for converting full-width English letters into half-width forms. In modern life, we often come into contact with English letters, and we often need to input English letters when using computers, mobile phones and other devices. However, sometimes we encounter full-width English letters, and we need to use the half-width form. So, how to convert full-width English letters to half-width form? Here are some practical tips for you. First of all, full-width English letters and numbers refer to characters that occupy a full-width position in the input method, while half-width English letters and numbers occupy a full-width position.

How to remove the date that appears automatically when printing from PPT handouts How to remove the date that appears automatically when printing from PPT handouts Mar 26, 2024 pm 08:16 PM

1. Let me first talk about the method I used at the beginning, maybe everyone is using it too. First, open [View]——]Remarks Template[. 2. A place where you can actually see the date after opening it. 3. Select it first and delete it. 4. After deleting, click [Close Master View]. 5. Open the print preview again and find that the date is still there. 6. In fact, this date was not deleted here. It should be in the [Handout Master]. Look at the picture below. 7. Delete the date after you find it. 8. Now when you open the preview and take a look, the date is no longer there. Note: In fact, this method is also very easy to remember, because the printed handouts are handouts, so you should look for the [Handout Master].

How to convert qq music to mp3 format Convert qq music to mp3 format on mobile phone How to convert qq music to mp3 format Convert qq music to mp3 format on mobile phone Mar 21, 2024 pm 01:21 PM

QQ Music allows everyone to enjoy watching movies and relieve boredom. You can use this software every day to easily satisfy your needs. A large number of high-quality songs are available for everyone to listen to. You can also download and save them. The next time you listen to them, you don’t need an Internet connection. The songs downloaded here are not in MP3 format and cannot be used on other platforms. After the membership songs expire, there is no way to listen to them again. Therefore, many friends want to convert the songs into MP3 format. Here, the editor explains You provide methods so that everyone can use them! 1. Open QQ Music on your computer, click the [Main Menu] button in the upper right corner, click [Audio Transcoding], select the [Add Song] option, and add the songs that need to be converted; 2. After adding the songs, click to select Convert to [mp3]

Detailed explanation of the implementation method of converting PHP months to English months Detailed explanation of the implementation method of converting PHP months to English months Mar 21, 2024 pm 06:45 PM

This article will introduce in detail how to convert months in PHP to English months, and give specific code examples. In PHP development, sometimes we need to convert digital months to English months, which is very practical in some date processing or data display scenarios. The implementation principles, specific code examples and precautions will be explained in detail below. 1. Implementation principle In PHP, you can convert digital months into English months by using the DateTime class and format method. Date

PHP Tutorial: How to convert int type to string PHP Tutorial: How to convert int type to string Mar 27, 2024 pm 06:03 PM

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

How to convert full-width English letters into half-width letters How to convert full-width English letters into half-width letters Mar 25, 2024 pm 02:45 PM

How to convert full-width English letters into half-width letters In daily life and work, sometimes we encounter situations where we need to convert full-width English letters into half-width letters, such as when entering computer passwords, editing documents, or designing layouts. Full-width English letters and numbers refer to characters with the same width as Chinese characters, while half-width English letters refer to characters with a narrower width. In actual operation, we need to master some simple methods to convert full-width English letters into half-width letters so that we can process text and numbers more conveniently. 1. Full-width English letters and half-width English letters

See all articles