Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the trunc () function of Oracle's self-supplement

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1.TRUNC (for dates)

The date value truncated by the TRUNC function for the specified element.

The specific syntax format is as follows:

TRUNC (date [, fmt])

Where:

Date one date value

Fmt date format, which will be truncated by the specified element format. Ignore it and it is truncated by the most recent date

The following is the use of this function:

TRUNC (TO_DATE ('24-Nov-1999 08:00 pm'),' dd-mon-yyyy hh:mi am') = '24-Nov-1999 12:00:00 am'TRUNC (TO_DATE (' 24-Nov-1999 08:37 pm','dd-mon-yyyy hh:mi am'), 'hh') =' 24-Nov-1999 08:00:00 am'trunc (sysdate,'yyyy')-returns to the first day of the year. Trunc (sysdate,'mm')-returns the first day of the month. Trunc (sysdate,'d')-returns the first day of the current week. Trunc (sysdate,'dd')-returns the current year, month and day

2.TRUNC (for number)

The TRUNC function returns the processed value, and its working mechanism is very similar to the ROUND function, except that the function does not round off the parts before or after the specified decimal number, but truncates them all.

The specific syntax format is as follows

TRUNC (number [, decimals])

Where:

The value of number to be intercepted

Decimals indicates that the number of digits after the decimal point should be retained. Optional, ignore it and truncate all decimal parts

The following is the use of this function:

TRUNC (89.985) = 89.98TRUNC (89.985) = 89TRUNC (89.985) = 80

Note: the second parameter can be negative, which is truncated after the specified number of places to the left of the decimal point, that is, it is marked with 0. Similar to rounding, for example, if the parameter is 1, it is rounded to ten, if it is-1, it is rounded to ten, and so on.

The above is the use of the trunc () function of Oracle self-supplement introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report