ORACLE function introduction

ORACLE function introduction (1) Reply: 0 Read: 143 2009-02-18 15:52:52 Single value function returns a single value in the query, which can be applied to select, where clause, start with and connect by clauses and having clause. (1). Number Functions (Number Functions) Numerical functions input numeric parameters and return numeric values. The return value of most of these functions supports 38 decimal points, such as: COS, COSH, EXP, LN, LOG, SIN, SINH, SQRT, TAN, and TANH support 36 decimal points. ACOS, ASIN, ATAN, and ATAN2 support 30 decimal points. 1. MOD(n1,n2) returns the remainder of n1 divided by n2. If n2=0, it returns the value of n1. For example: SELECT MOD(24,5) FROM DUAL; 2. ROUND(n1[,n2]) returns the value of n1 after rounding n2 to the right of the decimal point. The default value of n2 is 0. If n2 is negative, it will be rounded to the left of the decimal point. The corresponding bit (although the value of n2 must be an integer mentioned in the oracle documents, in fact, the judgment here is not rigorous during execution. Even if n2 is a non-integer, it will automatically round n2 for processing, but I Other parts mentioned in the document that must be whole need special attention, if it is not whole, an error will be reported). For example: SELECT ROUND(23.56),ROUND(23.56,1),ROUND(23.56,-1) FROM DUAL; 3. TRUNC(n1[,n2] returns the value of n1 truncated to n2 decimal places, the default setting of n2 Is 0, when n2 is the default setting, n1 will be truncated to an integer, if n2 is negative, it will be truncated to the corresponding digit to the left of the decimal point. For example: SELECT TRUNC(23.56),TRUNC(23.56,1), TRUNC(23.56,-1) FROM DUAL; (two). Character Functions Returning Character Values ​​(Character Functions Returning Character Values) This type of function returns the same type as the input type. l The length of the returned CHAR type value does not exceed 2000 bytes; l The length of the returned VCHAR2 type value does not exceed 4000 bytes; if the character length that should be returned above exceeds, oracle will not report an error but will directly truncate to the maximum supported length. . l The length of the returned CLOB type value does not exceed 4G; for the CLOB type function, if the return value length exceeds, oracle will not return any error but directly throw an error. 1. LOWER(c) changes the characters in the specified string to lowercase, supports CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, NCLOB types such as: SELECT LOWER('WhaT is tHis') FROM DUAL; 2. UPPER(c) will The characters in the specified string become uppercase, support CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, NCLOB types. For example: SELECT UPPER('WhaT is tHis') FROM DUAL; 3. LPAD(c1,n[,c2]) returns the specified For a string with length=n, there are several points to note: l If nc1.length and c2 is null, add the character length from left to right with a space to n and return; l if n>c1.length and c2 is not null , Add the length of c1 to n from left to right with the specified character c2 and return; for example: SELECT LPAD('WhaT is tHis',5), LPAD('WhaT is tHis',25), LPAD('WhaT is tHis', 25,'-') FROM DUAL; Finally, everyone guesses again, if n<0, what will happen 4, RPAD(c1,n[, c2]) returns a string with the specified length=n, basically the same as above, but the supplementary characters are from right to left, which is the opposite of the above; for example: SELECT RPAD('WhaT is tHis',5),RPAD('WhaT is tHis',25),RPAD('WhaT is tHis',25,'-') FROM DUAL; 5. TRIM([[LEADING||TRAILING||BOTH] c2 FROM] c1) Haha, the way I am invincible Confused, this place is a bit clearer by looking at the picture. It looks very complicated, but it is simple to understand: l If no parameters are specified, oracle removes c1 head and tail spaces. For example: SELECT TRIM(' WhaT is tHis') FROM DUAL; l If c2 is specified, oracle removes c1 head and tail c2 (This suggestion for careful testing, there are many different situations) For example: SELECT TRIM('W' FROM'WhaT is tHis w W') FROM DUAL; l If the leading parameter is specified, the c1 header c2 will be removed. For example: SELECT TRIM(leading'W' FROM'WhaT is tHis w W') FROM DUAL; l If the trailing parameter is specified, c1 tail c2 will be removed. For example: SELECT TRIM(trailing'W' FROM'WhaT is tHis w W') FROM DUAL; l If both parameters are specified, c1 head and tail c2 will be removed (is there any difference from not specifying it? No difference!) For example: SELECT TRIM(both'W' FROM'WhaT is tHis w W') FROM DUAL; Note: c2 length=1 6, LTRIM(c1[, c2]) Tens of millions of tables think it looks like the above one, and the function is similar to the above. This function intercepts the same characters as the specified string c2 from the left side of the string c1 and returns it. If c2 is empty, spaces are intercepted by default. For example: SELECT LTRIM('WWhhhhhaT is tHis w W','Wh') FROM DUAL;

Guess you like

Origin blog.csdn.net/jifeijixufly/article/details/4941094