A few functions in Oracle that deal with the number of decimal places, take the decimal places, the Oracle query function

Source: Internet
Author: User

about several Oracle functions that handle the number of decimal places ()1. Take a few decimals roundedSelect round(1.2345,3) fromdual; Results:1.2352. Keep two decimal places, onlySelectTrunc1.2345,2) fromdual; Results:1.23SelectTrunc1.2399,2) fromdual; Results:1.233take an integer to return the largest integer greater than or equal to x: SQL>         SelectCeil (23.33) fromdual; Results: -returns the largest integer equal to or less than x: SQL>         Select          Floor(23.33) fromdual; Results: atreturns the x value of the Y-bit rounded to the right of the decimal point: Rcund (x,[y]) SQL>         Select         round(23.33) fromdual; Results: atreturns the X value of the truncated to Y decimal places: Trunc (x,[y]) SQL>         SelectTrunc23.33) fromdual; Results: atformat the number the following is NumberExamples forThe To_charfunction. To_char (1210.73,'9999.9') wouldreturn '1210.7'To_char (1210.73,'9,999.99') wouldreturn '1,210.73'To_char (1210.73,'$9,999.00') wouldreturn '$1,210.73'To_char ( +,'000099') wouldreturn '000021'To_char Function Special usage to_char (sysdate,'D') The day of the week To_char (Sysdate,'DD'the day of the month To_char (Sysdate,'DDD'the first day of the year To_char (Sysdate,'ww'To_char (Sysdate), the first weeks of the year,'mm'To_char (Sysdate), the first month of the year,'Q') The quarter of the year To_char (Sysdate,'yyyy'For example, to find a time for the first day of the week can be SQL> SelectTo_char (To_date ('20070101','YYYYMMDD'),'D') fromdual;1. InStr in Oracle/in Plsql, the InStr function returns the position of the string to intercept in the source string. The syntax is as follows: InStr (string1, string2[, Start_position [, Nth_appearance]]) string1 the source string to find in this string. String2 the string to find in string1. Start_position represents where string1 is starting to find. This parameter is optional if omitted by default to 1. The string index starts at 1. If this parameter is positive, it is retrieved from left to right, and if this parameter is negative, right-to-left, returns the starting index of the string to find in the source string. Nth_appearance representative to find the first occurrence of the string2. This parameter is optional, and if omitted, the default is1if negative, the system will give an error. Note: If String2 is not found in String1, the InStr function returns 0. Applies To: Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g Example:SelectInStr'ABC','a') fromDual--returns 1SelectInStr'ABC','BC') fromDual--returns 2SelectInStr'ABC abc','a',1,2) fromDual--returns 5SelectInStr'ABC','BC',-1,1) fromDual--returns 2SelectInStr'ABC','D') fromDual--returns 0Note: This function can also be used to check if the String1 contains String2, if the return 0 means not included, otherwise the inclusion is represented. 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.