Vous êtes sur la page 1sur 6

ADD_MONTHS(date, count) Adds count months to date. GREATEST(date1, date2,date3, .) Picks latest date from list of dates.

LEAST(date1, date2,date3, .) Picks earliest date from list of dates. LAST_DAY(date) Gives date of last day of month that date is in. MONTHS_BETWEEN(date2,date1) Gives date2-date1 in months (Can be fractional) NEXT_DAY(date, day ) Gives date of next day after date, where day is Monday, Tuesday, and so on. NEW_TIME(date, this , other ) Gives the date(and time) in this time zone. This will be replaced by a three letter abbreviation for the current tim e zone. Other will be replaced by a three-letter abbreviation for the other time zone for which you d like to know the time and date. Time Zones are as follows: AST/ADT Atlantic Standard/daylight time BST/BDT Bering Standard/daylight time CST/CDT Central Standard/daylight time EST/EDT Eastern Standard/ daylight time GMT Greenwich Mean Time HST/HDT Alaska-Hawaii Standard/ daylight time MST/MDT Mountain Standard/ daylight time NST Newfoundland Standard Time PST/PDT Pacific standard/ daylight time YST/YDT Youkon standard/ daylight time

Examples: ADD_MONTHS(date, count) -

Adds count months to date.

SQL> SELECT ADD_MONTHS(SYSDATE,2) FROM DUAL; ADD_MONTH --------06-FEB-08 SQL> SELECT ADD_MONTHS('12-MAR-07',3) FROM DUAL; ADD_MONTH --------12-JUN-07 SQL> SELECT ADD_MONTHS('01-JAN-08',-12) FROM DUAL; ADD_MONTH --------01-JAN-07 Example: GREATEST(date1, date2,date3, .) Picks latest date from list of dates.

SQL>SELECT GREATEST('12-MAR-05','14-JAN-07','11-JAN-80') FROM DUAL; GREATEST( --------14-JAN-07

Example : LEAST(date1, date2,date3, .)

Picks earliest date from list of dates.

SQL> SELECT LEAST('12-MAR-05','14-JAN-07','11-JAN-80') FROM DUAL; LEAST('12 --------11-JAN-80

Example: LAST_DAY(date) Gives date of last day of month that date is in. SQL> SELECT LAST_DAY(SYSDATE) FROM DUAL; LAST_DAY( --------31-DEC-07 SQL> SELECT LAST_DAY('01-FEB-08') FROM DUAL; LAST_DAY( --------29-FEB-08 Examples: MONTHS_BETWEEN(date2,date1) Gives date2-date1 in months SQL> SELECT MONTHS_BETWEEN('12-MAR-07','12-MAR-05') FROM DUAL; MONTHS_BETWEEN('12-MAR-07','12-MAR-05') --------------------------------------24 Example : NEXT_DAY(date, day ) Gives date of next day after date, where day is Monday, Tuesday, and so on. SQL> SELECT NEXT_DAY(SYSDATE,'SUNDAY') FROM DUAL; NEXT_DAY( --------09-DEC-07 Example: NEW_TIME(date, this , other ) SQL> SELECT NEW_TIME('12-DEC-07','GMT','NST') FROM DUAL; NEW_TIME( --------11-DEC-07 SQL> SELECT TO_CHAR(NEW_TIME(SYSDATE,'GMT','AST'),'DD-MON-YYYY HH:MI:SS') FROM D UAL; TO_CHAR(NEW_TIME(SYS -------------------05-DEC-2007 08:54:12 Round(date, format ) without format specified, rounds a date of 12 A.M(midnight, the beginning of the day) if time of date is before noon; otherwise, rounds up to n

ext day. Example: SELECT TO_DATE('19-DEC-07')-ROUND(SYSDATE)FROM DUAL; Output: 2 Trunc(date, format ) without format specified, sets a date to 12 A.M. (midnight, th e beginning of that day). Example: SELECT TO_DATE('19-DEC-07')-trunc(SYSDATE)FROM DUAL; Output: 2 Numeric Functions

Numeric Functions: ABS(data) Example: Output: 5000 CEIL(data) Example: Output: 124 FLOOR(data) Example: Output: 123 LN(data) Example: LOG(b,data) Example: Output: 2 MOD(data,Y) Example: Output: 1 POWER(data, Y) Example: Output: 8 ROUND(data, n) nded. Example: Output: 124 Example: Output: 123.6 SQRT(data) Example: Select Output: 8 TRUNC(data,n) Example: Output: 123 Example: Dual; Output: 123.5 Returns the absolute value of data(i.e. Positive value) Select ABS(-5000) from Dual; Returns the smallest integer greater than or equal to data. Select CEIL(123.55) from Dual; Returns the largest integer less than or equal to data. Select FLOOR(123.55) from Dual; Returns the natural logarithm of data. Select ln(12) from Dual; Returns the base b logarithm of data. Select LOG(10,100) from Dual; Returns the modulus of dividing data by Y. Select MOD(7,3) from Dual; Returns the data raised to the power of Y. Select Power(2,3) from Dual; Where n is the number of decimal places to which the data is rou Select ROUND(123.55,0) from Dual; Select ROUND(123.55,1) from Dual; Returns the square root of data. SQRT(64) from Dual; Where n is the number of decimal places for truncation. Select TRUNC(123.55,0) from Dual; Select TRUNC(123.55,1) from

Trigonometric Functions: COS(x) Returns the Cosine of x in radian. Example: Select COS(45) from Dual;

SIN(x) Returns Example: Select TAN(x) Returns Example: Select COSH(x) Returns Example: Select SINH(x) Returns Example: Select TANH(x) Returns Example: Select

the Sine of x in radian. SIN(45) from Dual; the Tangent of x in radian. TAN(45) from Dual; the hyperbolic cosine of x. COSH(45) from Dual; the hyperbolic SINH(45) from the hyperbolic TANH(45) from sine of x. Dual; tangent of x. Dual;

Character Functions: INITCAP(data) Will convert the first letter of the string to uppercase. Example: Select INITCAP( kumar ) from Dual; Output: Kumar LENGTH(data) Will return the length of the string. Example: Select LENGTH( Kumar ) from Dual; Output: 5 SUBSRT(data, X, Y) Will extract Y characters starting from the Xth Character of data. Example: Select SUBSTR( India ,2,3) from Dual; Outptu: ndi INSTR(data,X) Will find the location of string X in the string data. Example: Select INSTR( Computer , ter ) from dual; Output: 6 GREATEST(expr1, expr2, expr3 .) Displays the greatest value from a group of expr essions. Select GREATEST(122,456,9,45,900) FROM DUAL; Output: 900 LEAST(expr1, expr2, expr3, ) Displays the least value from a group of express ions. Select LEAST(122,456,9,45,900) FROM DUAL; Output: 9 Conversion Functions: There are three elementary Oracle functions whose purpose is to convert one data type into another. 1. 2. 3. TO_CHAR transforms a DATE or NUMBER into a character string. TO_DATE transforms a NUMBER, CHAR or VARCHAR2 into a DATE. TO_NUMBER transforms a CHAR or VARCHAR2 into a NUMBER.

TO_CHAR (data, format) Example: Select TO_CHAR(17145, $099,999 ) from Dual; Output: $017,145 Number Convert into Character String. Select To_Char(sysdate, day ) from Dual; Output : Monday Date convert into Character String. TO_DATE (char, format):

Example: Select to_date('12-MAR-1979','DD-MON-YYYY') FROM DUAL; Output: 12-Mar-79 Char convert into Date. TO_NUMBER(CHAR/VARCHAR2, NUMBER) Example: select TO_NUMBER('100.00', '9G999D99') from dual; Output: 100 select TO_NUMBER('1000.000', '9G9999D999') from dual; Output: 1000 Miscellaneous Functions The following are some of the miscellaneous functions supported by Oracle. ? ? ? ? Uid User Nvl Vsize

Uid: This function returns the integer value corresponding to the user currently logged in. The following example is illustrative. Select Uid from dual; Output: 26 User : This function returns the login s user name, which is in varchar2, datatype . Consider the following example. Select user from dual; Output: SCOTT Null Value(Nvl) : The null value function is used in cases where we want to cons ider Null values as zero. select nvl(comm,0) from emp; Vsize: The functions is vsize(expr). It returns the number of bytes in the expre ssions. If expression is Null, it returns Null. Select vsize( hello ) from dual; Output: 5

Group Functions: A group function returns a result based on a group of rows. Some of these are ju st purely mathematical functions. The group functions supported by Oracle are su mmarized below:

Function Description AVG(Distinct| All | x) Average value of x AVG function can be used on numeric data character data that contains only numer ics.

Example: Select avg(sal) from emp;(all salary) Select Avg(distinct sal) from emp;(only Different salary) COUNT Number of rows in the result SELECT Count(sal) from emp; (Does not count null values) MAX(Distinct|All|x) MIN(Distinct|All|x) Maximum value of x Max and Min functions can be used on any type of data. SELECT MAX(SAL),MAX(ENAME),MIN(SAL),MIN(COMM)From Dual; SUM(Distinct|All|x) Sum of values of x. Sum function can be used on numeric data. SELECT SUM(SAL),SUM(COMM) FROM DUAL; SELECT SUM(Distinct sal) from dual; STDDEV(Distinct|All|x) Standard Deviation of x SELECT STDDEV(SAL) FROM DUAL; COUNT(*) It Counts all rows inclusive of duplicate and Nulls. SELECT COUNT(*) FROM EMP; COUNT(ColumnName) It counts all rows in the column without including nulls . SELECT COUNT(COMM) FROM EMP;

Vous aimerez peut-être aussi