Summary of Oracle Database Common Functions

String functions:

  1. Splicing function: concat(p1,p2), the content p1 and p2 are seamlessly spliced, and "||" can also be used instead
  2. Length of statistics: length(p1), the length of the string of the content of p1
  3. Padding function: left padding: lpad(p1,n,p2), use p2 to perform left padding on p1, the total length is n; the same is true for right padding function
  4. Uppercase and lowercase functions: all uppercase: upper(p1), the letters in the content p1 characters are all uppercase; all lowercase: lower (p1) The letters in the content p1 characters are all lowercase; the first letter is capitalized: initcap(p1): the first character of the content p1 capital letters 
  5. Intercept function:
  • trim(p1 from p2): truncate p1 before and after p2, note that p1 must be a character
  • Left truncation: ltrim(p1, p2): truncate any character containing p2 from the left side of p1, stop truncating if the character to be truncated is gone, and truncated right rtrim() Similarly eq:p1=' Shanghai tap water comes from the sea 'p2='Shanghai comes' Return result: 'Tap water comes from'

    6. Intercept substring function: substr(p1, start, [len]) intercepts from the start bit, len indicates the length of interception, if len is not written, it is intercepted to the end by default,

    Note: when a.start is 0 or 1, it starts from the beginning, b.start can be negative, and counts start from back to front and starts to intercept to the end

    7. Retrieval function: instr(p1,p2,[[m],[n]]), the function returns the position of p2 substring in p1 (no substring returns 0)

    Parameter description: m means to search backward from the mth character of p1, n means the number of occurrences of p2

Numeric function:

    In order to consider the portability and compatibility of the database, oracle provides other types

other types in oracle Corresponds to the data type in oracle
numeric(p,s) nunber(p,s)
decimal(p,s)/dec(p,s) number(p,s)
interger/int number(38)
smallint number(38)
float number
double precision number
real 19 significant digits of number

Note: p is how many digits, s how many digits

1. Rounding function: round(p, s), round p, retain s decimal places, s can be negative, which is equivalent to retaining s digits before the decimal point

2. Intercept function: trunc(p,s), intercept p, retain n digits after the decimal point

3. The remainder function: mod(m,n), m performs the remainder operation on n

4. Up and down rounding function: ceil(p)/floor(p), take the smallest integer greater than or equal to m/take the largest integer less than or equal to m

Date manipulation functions:

date: date type, the default format: dd=mon-rr, occupies 7 bytes, the first byte represents the century + 100, and the following bytes represent the year, month, day, hour, minute, and second respectively

timestamp: timestamp type, the maximum size is 11 bytes, the first 7 bytes are the same as date, and the last four are used to store the accuracy, which can be accurate to nanoseconds

Keywords: sysdate: returns the current system time; systimestamp: returns the timestamp type of the current system time

Format: yyyy year, MM/mm month, DD day HH/hh hour, mi minute, ss second AM means morning and afternoon, day, dy means week. d: indicates the day of the week ddd: indicates the day of the year

Note: Oracle data is case insensitive

    1.to_char(p1,fmt): Display p1 in fmt format (usually used in query statements)

    2.to_date(p1,fmt): According to the format of fmt, turn the string into a date type (usually used in adding and modifying statements)

    3.last_day(p1): Query the last day of the month where p1 is located

    4.add_months(p1,n): View the date n months after p1, n can be positive or negative, decimal (it will be automatically intercepted)

    5.months_between(p1, p2): Calculate the number of months between p1 and p2, the result may be positive, decimal or negative

    6.next_day(date, num): Calculate the time from a certain date to the next day of the week, the range of num is 1~7, which means Sunday to Saturday

    7.extract (component from date): extract the components in date, the components are year, month, day, hour, minute, second

Note: The date type can extract the first three components, and timestamp can extract all components

   8.least(p1,p2,...)/greatest(p1,p2,...) compares multiple parameters, the minimum/maximum value, the parameters are of the same type or can be converted to the same type by default

Null value handler:

    1.nvl(p1,p2): If the value of p1 is null, p2 will be used, and if it is not null, it will be its own value

    2.nvl2(p1,p2,p3): If p1 is null, use p3, if not null, use p2

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325502167&siteId=291194637