PL / SQL function

One

Brief introduction

Function syntax is:

 FUNCTION(ARG,...,arg N)

Data type action functions: arithmetic functions, string functions; date function;

The return value can be divided into: packet-way function and function;

two

One-way function

1, character function

a: Returns value char character functions provided

CHAR (n): Returns the binary characters equal to n;

CONCAT (char1, char2); char1 and returns the result to phase c Char2 connected;

INITCAP (char): char the first letter of each word capitalized and return;

LOWER (char): The char and return all letters to lower case;

LPAD (char1, n, [char2]): plus sequence of characters to the left of char1 char2 until the total length of the character is newly generated N, and then returns the new string. The default value is a single table space CHAR2

LTRIM (char, [set]) char from the left belong to set long removed alphabetic character set, the first set to the character that is not, and returns the new string, the default value is set spaces

NLS_INTCAP (char [, 'nlsparams']): the first letter of all words of the char changed to uppercase, lowercase letters other return;

NLS_LOWER (CHAR [, 'nlsparams']): all upper case letters and returns into the CHAR.

NLS_UPPER (char [, 'nlsparams']): all upper case letters and returns into the char.

REPLACE (char, search_string [, replacement_string]): replacement_string alternatively with char string serach_string all sub.

RPAD (char1, n [, char2]): char1 plus the right character sequence char2 until the total length of the newly generated character string is n, then returns the new string.

RTRIM (char, [set]): char string is removed from the right side of the letters belonging to the set character set, does not belong to the first set up in the string, and returns the new

String.

SOUNDEX (char): Returns a string containing the phonetic representation of char

SUBSTR (char, m [, n]): the m-th character from the beginning to take char n characters constituting char substring and returns.

SUBSTRB (char, m [, n]): a function of the same, but its variables m and n in bytes, and the SUBSTR is characters.

TRANSLATE (char, from, to): each of the char from belonging with the respective character to replace it and returns the new string.

UPPER (CHAR): all capitalized letters of char and returns;

b: return value of the numeric character function

ASCII (char): Returns the char first byte decimal notation;

INTER (char1, char2 [, n [, m]] the first n characters of char1 start searching for the m-th occurrence of char2 and return char2 m-th arise, and return the first character of the m-th occurrence of char2 of in the position char1;

INTERB (char1, char2 [, n [, m]]: Function same as INSTR, except that INSTRB in bytes;

LENGTH (char): returns the length of the character string of the char;

LENGTHB (CHAR): returns the byte length of the string of char.

example

SELECT SUBSTR('ABCDEFG',3,2)
FROM DUAL

2. Date function (except MONTHS_BETWEEN, return values ​​are NUMERICAL date)

ADD_MONTHS (d, n): d date calculated by the date after n months and returns.

LAST_DAY (d): d last day of the month to calculate the date;

MONTHS_BETWEEN (d1, d1): calculate the number of months between D1 and D2, if later than D1 D2, the result is positive;

NEXT_TIME (d, z1, z2): z1 return date and time zone d corresponding date and time in the time zone z2;

NEXT_DAY (D, CHAR): char is 'SUNDAY' to a 'SATURDAY' in. This function returns after the first date d refers char Sunday are written;

ROUND (d, [fmt]): fmt specifies the format of the model unit, the date and returns rounding d;

SYSDATE: returns the current date and time, the function has no parameters

TRUNC (d, [fmt]): fmt specifies the format of the model unit, will be intercepted and return date d.

3. numerical function

ABS (N): returns the absolute value of n

CELL (n): Returns greater than or equal to the smallest integer N

COS (n): Returns the cosine value of n

COSH (n): Returns the n Cosh;

EXP (n): Returns the value of the en

FLOOR (n): returns the largest integer less than or equal to n

LN (n): Returns the natural logarithm of n

LOG (m, n) Returns the number of n to m is in the bottom

MOD (m, n): Returns the remainder of m divided by n;

POWER (m, n): Returns the m-th power of n, if m is negative, then n must be an integer;

SIGN (n): when n <0, or -1; and when n = 0, 0 is returned; and when n> 0, the return 1

SINH (n): Returns the hyperbolic sine of n.

SIN (n): n sine Returns

SQRT (n): returns the square root of n;

TAN (n): Returns the tangent of n

TANH (n): Returns the hyperbolic tangent n

TRUNC (n [, m]): Returns the value of n m-bit truncated, and when m is omitted, the truncation 0, when n is negative, the left of the decimal digits truncated m;

3. Conversion Functions

Conversion from one type into another type

CHARTOROWID (char): char is converted from the value of the char is ROWID type;

CONVERT (char, dest_char_se [, source_char_set]): the char from the source character to a target character set source_char_set set dest_char_set;

HEXTOROW (char): converting the char into a hexadecimal type RAW type;

RAWTOHEX (RAW): The raw type conversion from the RAW to find the value of 16 hexadecimal characters;

ROWIDTOCHAR (rowid): rowid converted from the type value into the type VARCHAR2 ROWID

TO_CHAR (d [, fmt [, 'nlsparams']]) in accordance with a predetermined date format fmt d-converted by the date value to a value type of VARCHAR2.

T0_CHAR (n [, fmt [, 'nlsparams'): values ​​can be selected in accordance with the format fmt, the n-type digital-converted into a numeric type VARCHAR2 familiar.

TO_DATE (char [, fmt [, 'nlsparams']]); fmt specified date format according to a CHAR char is converted into numerical dates;

TO_MULTI_BYTE (char): all of the char is converted into single-byte multi-byte;

TO_NUMBER (char, [, fmt, [nlsparams]]): the char is converted into numerical type

TO_SINGAL_BYTE (char): All multi-byte character converting the char into the corresponding single byte character;

5. Other functions

DUMP (expr, [, return_format [, start_position [, length]]]); return values ​​are contained VARCHAR2 type code, and the length in bytes of the expression expr internal representation unit.

GREATEST (expr [, expr]): return all the maximum expression in the parameter table, all expressions after the first numerical expressions are as a type of the first expression implicit conversion.

LEAST (expr [, expr]): returns the minimum value of all the parameters in the expression

NVL (expr1, expr1): If expr1 is null, then the value returned expr2; expr1 if not empty, return expr1;

USER: Returns the current oracle user; 

UID: Returns a unique integer mark Shaw before a user;

USERNV (option): Returns the current session information VAR1CH2 types of transactions;

VSIZE (expr): returns the number of bytes of Formula large expression expr internal table;

Three: group function

COUNT ({* | [DISTINCE | ALL] expr): function that returns the query line

MIN / MAX (DISTINCE | ALL expr [): Returns the minimum / maximum expression;

GROUP BY: This is the group

HAVING: a packet conditions

 

 

 

 

Published 153 original articles · won praise 15 · Views 150,000 +

Guess you like

Origin blog.csdn.net/beyond911/article/details/103841196