<ul><li>Operators and Built-in Functions </li></ul><ul><li>  </li></ul>
<ul><li>Operators </li></ul><ul><li>Operators are used to manipulate data using the select statement.  </li></ul><ul><ul><...
<ul><li>Arithmetic Operators </li></ul><ul><li>Operators  are   +,  -,  *,  /   </li></ul><ul><li>SELECT * FROM EMP WHERE ...
<ul><li>Logical Operators </li></ul><ul><li>AND  (logical AND),  OR  (logical OR) and  NOT  (logical NOT). </li></ul><ul><...
<ul><li>Relational Operators   </li></ul><ul><li>=  Equal to </li></ul><ul><li><>, !=,^= Not Equal to </li></ul><ul><li>< ...
<ul><li>Examples for Relational Operators: (= , <>) </li></ul><ul><li>SELECT * FROM EMP  WHERE DEPTNO = 10; </li></ul><ul>...
<ul><li>Example for > ,>=, <. <= </li></ul><ul><li>SELECT * FROM EMP WHERE  SAL > 3000 ; </li></ul><ul><li>The above examp...
<ul><li>Special Operators </li></ul><ul><li>  LIKE, BETWEEN AND, IN, ANY and ALL </li></ul><ul><li>  Examples: </li></ul><...
String Operators <ul><li>  </li></ul><ul><li>%   (percentage) </li></ul><ul><li>_  (underscore) </li></ul><ul><li>||  (con...
<ul><li>Examples:  </li></ul><ul><li>SELECT * FROM EMP WHERE ENAME LIKE ‘E%’; </li></ul><ul><li>The above example will sel...
Built-in SQL functions <ul><li>SQL provides a number of predefined functions that can be called from within an SQL stateme...
Types of Functions <ul><li>  </li></ul><ul><li>Ø        Character functions </li></ul><ul><li>Ø        Arithmetic function...
Character Functions <ul><li>CHR </li></ul><ul><li>Syntax: CHR(x) </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the ...
<ul><li>What is DUAL? </li></ul><ul><li>Dual is a small Oracle table created for testing functions or doing quick calculat...
<ul><li>CONCAT </li></ul><ul><li>  </li></ul><ul><li>Syntax: CONCAT (String1, String 2) </li></ul><ul><li>  </li></ul><ul>...
<ul><li>INITCAP </li></ul><ul><li>  </li></ul><ul><li>Syntax: INITCAP( String ) </li></ul><ul><li>  </li></ul><ul><li>Purp...
<ul><li>LOWER </li></ul><ul><li>  </li></ul><ul><li>Syntax: LOWER(String) </li></ul><ul><li>  </li></ul><ul><li>Purpose: <...
<ul><li>UPPER </li></ul><ul><li>  </li></ul><ul><li>Syntax: UPPER(string) </li></ul><ul><li>  </li></ul><ul><li>Purpose  <...
<ul><li>LPAD </li></ul><ul><li>Syntax: LPAD(String1,  x [,string2]) </li></ul><ul><li>Purpose : </li></ul><ul><ul><li>Retu...
<ul><li>SELECT LPAD (‘have a good day’, 20, ‘XY’) “Demo” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Demo </l...
<ul><li>RPAD </li></ul><ul><li>  </li></ul><ul><li>Syntax: RPAD(String1,x[,string2]) </li></ul><ul><li>  </li></ul><ul><li...
<ul><li>SELECT RPAD(‘Cricket’, 10, ‘AB’) “Second” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Second </li></u...
<ul><li>RTRIM </li></ul><ul><li>  </li></ul><ul><li>Syntax: RTRIM(String1[,string2]) </li></ul><ul><li>  </li></ul><ul><li...
<ul><li>SELECT RTRIM(‘This is a stringxxxxx’, ‘x’) “Second” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Secon...
<ul><li>TRIM  </li></ul><ul><li>This function can used instead of LTRIM and  RTRIM </li></ul><ul><li>  </li></ul><ul><li>E...
<ul><li>REPLACE </li></ul><ul><li>Syntax: </li></ul><ul><li>REPLACE (String, search_str[, replace_str]) </li></ul><ul><li>...
<ul><li>SELECT REPLACE (‘This and That’, ‘Th’)”Second” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Second </l...
<ul><li>SUBSTR </li></ul><ul><li>  Syntax  :  SUBSTR ( string ,  a  [,  b ]) </li></ul><ul><li>  Purpose: </li></ul><ul><u...
<ul><li>SELECT SUBSTR ('He is a Good Boy', -5) &quot;Third&quot; from dual </li></ul><ul><li>  </li></ul><ul><li>Output: T...
<ul><li>TRANSLATE </li></ul><ul><li>Syntax: TRANSLATE ( string , from_str , to_str ) </li></ul><ul><li>Purpose: </li></ul>...
<ul><li>SOUNDEX </li></ul><ul><li>  </li></ul><ul><li>Syntax: Soundex( string ) </li></ul><ul><li>  </li></ul><ul><li>Purp...
Date Functions <ul><li>  The date functions take arguments of type DATE,  except  for the MONTHS_BETWEEN function, which r...
SYSDATE <ul><li>Syntax: SYSDATE </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the current date and time, of type DA...
ADD_MONTHS <ul><li>Syntax: ADD_MONTHS ( d,x  ) </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the date  d  plus  x  ...
MONTHS_BETWEEN <ul><li>Syntax:  MONTHS_BETWEEN(DATE1,DATE2) </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns the n...
LAST_DAY <ul><li>  Syntax: LAST_DAY( d) </li></ul><ul><li>Purpose:  </li></ul><ul><li>Return the date of last day of the m...
NEXT_DAY <ul><li>Syntax: NEXT_DAY(d, string) </li></ul><ul><li>Purpose  : </li></ul><ul><li>This function returns the date...
ROUND <ul><li>  </li></ul><ul><li>Syntax: ROUND(d,  [, format) </li></ul><ul><li>Purpose  : </li></ul><ul><ul><li>Returns ...
TRUNC   <ul><li>Syntax: TRUNC(d, [,format]) </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns the date d truncated ...
Date Arithmetic <ul><li>Applying the arithmetic operators to dates and numbers are described. </li></ul><ul><li>When one d...
Subtracting from Date <ul><li>Example 1: </li></ul><ul><li>SELECT TO_DATE('12-APR-71 12:00:00', 'DD-MON-YY HH24:MI:SS')  <...
<ul><li>Example 2: </li></ul><ul><li>  </li></ul><ul><li>SELECT TO_DATE('10-AUG-98') - TO_DATE('12-FEB-98') FROM DUAL; </l...
Conversion Functions   <ul><li>TO_NUMBER </li></ul><ul><li>  </li></ul><ul><li>Syntax: </li></ul><ul><li>TO_NUMBER( string...
TO_CHAR (WITH NUMBERS) <ul><li>  Syntax: </li></ul><ul><li>TO_CHAR( num,  [,format[, nlsparams ]]) </li></ul><ul><li>  Pur...
TO_CHAR (WITH DATE) <ul><li>Syntax: </li></ul><ul><li>TO_CHAR(d,[,format [,nlsparams]]) </li></ul><ul><li>Purpose: </li></...
<ul><li>Example 2: </li></ul><ul><li>SELECT TO_CHAR(HIREDATE, 'DDTH MONTH YEAR') &quot;JOINING DATE&quot;  </li></ul><ul><...
<ul><li>Group / Aggregate Functions </li></ul>
Group / Aggregate Functions <ul><ul><li>Group functions are those statistical functions, which gives information about a g...
<ul><li>AVG </li></ul><ul><li>Syntax: AVG([DISTINCT | ALL]col) </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the av...
<ul><li>COUNT  </li></ul><ul><li>Syntax  :  COUNT(*|[DISTINCT |ALL]col) </li></ul><ul><li>Purpose  :  </li></ul><ul><li>Co...
<ul><li>MAX </li></ul><ul><li>  Syntax: MAX([DISTINCT | ALL] coL) </li></ul><ul><li>Purpose  : </li></ul><ul><li>Returns t...
<ul><li>MIN </li></ul><ul><li>  Syntax  : MIN([DISTINCT | ALL] coL) </li></ul><ul><li>  Purpose:  Returns the maximum valu...
<ul><li>SUM </li></ul><ul><li>  Syntax  : SUM([DISTINCT | ALL] Col) </li></ul><ul><li>  Purpose: Returns the sum of the va...
<ul><li>Other / General Functions </li></ul><ul><li>DECODE </li></ul><ul><li>Syntax: DECODE( base_expr,   compare1, value1...
<ul><li>Example 1: </li></ul><ul><li>  SELECT DECODE(10, 10, 'TEN', 20, 'TWENTY', 30, 'THIRTY') &quot;MATCH&quot;  FROM DU...
<ul><li>Example 2: </li></ul><ul><li>  SELECT DECODE(50, 10, ‘TEN’, 20, ‘TWENTY’, 30, ‘THIRTY’, ‘NEW VALUE’) FROM DUAL; </...
<ul><li>GREATEST </li></ul><ul><li>Syntax  :  GREATEST (expr1[,expr2]…) </li></ul><ul><li>  Purpose : </li></ul><ul><li>Re...
<ul><li>LEAST </li></ul><ul><li>  Syntax  : LEAST(expr1 [, expr2]…) </li></ul><ul><li>  Purpose : </li></ul><ul><li>This f...
<ul><li>NVL </li></ul><ul><li>Syntax: NVL( expr1, expr2 ) </li></ul><ul><li>Purpose: </li></ul><ul><li>If  expr1  is NULL,...
<ul><li>UID </li></ul><ul><li>Syntax  : UID </li></ul><ul><li>  Purpose : Returns an integer that uniquely identifies the ...
<ul><li>USER </li></ul><ul><li>  Syntax  : USER </li></ul><ul><li>  Purpose : Returns a VARCHAR2 value containing the name...
Upcoming SlideShare
Loading in...5
×

Sql operators & functions 3

1,244

Published on

Published in: Economy & Finance, Technology
2 Comments
2 Likes
Statistics
Notes
  • Hi if you can share this doc to nriit.srinu@hotmail.com that would be very great and thank full.

    Thanks
    srinivas
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Very informative slide!! Its really help me lot and clear my doubts related to sql server operator. Thanks for sharing with us. The following link also helped me to complete my task. It is also helpful.
    http://mindstick.com/Articles/1216a153-610b-41f1-b51b-3035c069ffd7/?%E2%80%98SELECT%E2%80%99%20command%20with%20SQL%20operator

    Thanks everyone for yours nice post.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
1,244
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
2
Likes
2
Embeds 0
No embeds

No notes for slide

Sql operators & functions 3

  1. 1. <ul><li>Operators and Built-in Functions </li></ul><ul><li>  </li></ul>
  2. 2. <ul><li>Operators </li></ul><ul><li>Operators are used to manipulate data using the select statement. </li></ul><ul><ul><ul><ul><li>Arithmetic </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Relational </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Logical </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Special </li></ul></ul></ul></ul><ul><ul><ul><ul><li>String </li></ul></ul></ul></ul><ul><li>Built-in Functions </li></ul><ul><ul><ul><ul><li>Character </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Numeric </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Date </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Aggregate/Group </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Conversion </li></ul></ul></ul></ul><ul><ul><ul><ul><li>General/Other </li></ul></ul></ul></ul><ul><li>  </li></ul>
  3. 3. <ul><li>Arithmetic Operators </li></ul><ul><li>Operators are +, -, *, /   </li></ul><ul><li>SELECT * FROM EMP WHERE SAL + COMM > 3000; </li></ul><ul><li>The above Example will select the employee(s) whose salary + commission is </li></ul><ul><li>more than 3000. </li></ul><ul><li> SELECT * FROM EMP WHERE SAL – COMM > 2000; </li></ul><ul><li>The above example will select the employee(s) whose salary – commission is </li></ul><ul><li>more than 2000;  </li></ul><ul><li> SELECT * FROM EMP WHERE COMM > SAL * 10/100; </li></ul><ul><li>The above example will select the employee(s) whose commission is more </li></ul><ul><li>than 10% of their salary. </li></ul>
  4. 4. <ul><li>Logical Operators </li></ul><ul><li>AND (logical AND), OR (logical OR) and NOT (logical NOT). </li></ul><ul><li>SELECT * FROM EMP WHERE JOB = ‘CLERK’ AND DEPTNO=20 ; </li></ul><ul><li>The above example will select the employee(s) who is working in dept 10 and he </li></ul><ul><li>should be a CLERK. </li></ul><ul><li>In the above case, both the job and deptno should satisfy the given condition i.e., </li></ul><ul><li>both the conditions should be true. </li></ul><ul><li>SELECT ENAME FROM EMP WHERE JOB=’SALESMAN’ OR </li></ul><ul><li>JOB=’ANALYST’; </li></ul><ul><li>The above example will select the employee(s) whose JOB is either </li></ul><ul><li>SALESMAN or ANALYST. </li></ul><ul><li>SELECT * FROM EMP WHERE DEPTNO NOT IN (10, 20); </li></ul><ul><li>The above example will select the employee(s) who are not working in </li></ul><ul><li>department 10 and 20. </li></ul>
  5. 5. <ul><li>Relational Operators </li></ul><ul><li>= Equal to </li></ul><ul><li><>, !=,^= Not Equal to </li></ul><ul><li>< Less than </li></ul><ul><li>> Greater than </li></ul><ul><li>>= Greater than or </li></ul><ul><li><= Less than or Equal to </li></ul><ul><li> </li></ul>
  6. 6. <ul><li>Examples for Relational Operators: (= , <>) </li></ul><ul><li>SELECT * FROM EMP WHERE DEPTNO = 10; </li></ul><ul><li>  The above example will select the employee(s) who are working in </li></ul><ul><li>deptno 10; </li></ul><ul><li>  </li></ul><ul><li>SELECT * FROM EMP WHERE DEPTNO <> 10; </li></ul><ul><li>The above example will select the employee(s) who are not working in </li></ul><ul><li>deptno 10. </li></ul><ul><li>  </li></ul><ul><li>  </li></ul>
  7. 7. <ul><li>Example for > ,>=, <. <= </li></ul><ul><li>SELECT * FROM EMP WHERE SAL > 3000 ; </li></ul><ul><li>The above example will select the employee(s) who is getting salary from </li></ul><ul><li>3001 onwards. </li></ul><ul><li>SELECT * FROM EMP WHERE SAL >= 3000 ; </li></ul><ul><li>  The above example will select the employee(s) who is getting salary from </li></ul><ul><li>3000 onwards. </li></ul><ul><li>SELECT * FROM EMP WHERE SAL < 2000 ; </li></ul><ul><li>  The above example will select the employee(s) who is getting salary </li></ul><ul><li>below 2000; </li></ul><ul><li>SELECT * FROM EMP WHERE SAL <= 2000 ; </li></ul><ul><li>The above example will select the employee(s) who is getting salary 2000 </li></ul><ul><li>and less. </li></ul>
  8. 8. <ul><li>Special Operators </li></ul><ul><li>  LIKE, BETWEEN AND, IN, ANY and ALL </li></ul><ul><li>  Examples: </li></ul><ul><li>SELECT * FROM EMP WHERE ENAME LIKE ‘ALLEN’;  </li></ul><ul><li>The above example will select the employee(s) whose name is exactly like </li></ul><ul><li>‘ ALLEN’. Even it will not fetch the employee whose name is ‘allen’ or </li></ul><ul><li>‘ Allen’ or ‘Allen’. </li></ul><ul><li>  SELECT * FROM EMP WHERE SAL BETWEEN 1500 AND 3500 ; </li></ul><ul><li>  The above example will select the employee(s) who is getting salary </li></ul><ul><li>between 1500 and 3500; </li></ul><ul><li>ANY, IN and ALL operators will be explained more in SUB-QUERIES. </li></ul>
  9. 9. String Operators <ul><li>  </li></ul><ul><li>% (percentage) </li></ul><ul><li>_ (underscore) </li></ul><ul><li>|| (concatenation) </li></ul><ul><li>  </li></ul><ul><li>The above operators are used to compare the string values. </li></ul><ul><li>  </li></ul>
  10. 10. <ul><li>Examples: </li></ul><ul><li>SELECT * FROM EMP WHERE ENAME LIKE ‘E%’; </li></ul><ul><li>The above example will select the employee(s) who’s name starts with ‘E’ followed by any number of characters . </li></ul><ul><li>  </li></ul><ul><li>SELECT * FROM EMP WHERE ENAME LIKE ‘S_ _ _ _ _’; </li></ul><ul><li>The above example which uses the _(underscore) after ‘S’, will fetch the employee(s) who’s name starts with ‘S’ and whose length of name is exactly five characters . </li></ul><ul><li>SELECT ENAME||JOB||HIREDATE FROM EMP; </li></ul><ul><li>The above example will list the ENAME, JOB, HIREDATE column values joined together without any space in between. </li></ul><ul><li>  </li></ul>
  11. 11. Built-in SQL functions <ul><li>SQL provides a number of predefined functions that can be called from within an SQL statement. It is used to manipulate data items. </li></ul><ul><li>  </li></ul><ul><li>Advantages of Functions </li></ul><ul><li>  </li></ul><ul><li>Functions can be used to perform complex calculations on data. </li></ul><ul><li>  Functions can modify individual data items. </li></ul><ul><li>  Functions can very easily manipulate output for group of rows. </li></ul><ul><li>  Functions can alter date formats for display. </li></ul>
  12. 12. Types of Functions <ul><li>  </li></ul><ul><li>Ø       Character functions </li></ul><ul><li>Ø       Arithmetic functions </li></ul><ul><li>Ø       Date functions </li></ul><ul><li>Ø Conversion functions </li></ul><ul><li>Ø       Aggregate / Group functions </li></ul>
  13. 13. Character Functions <ul><li>CHR </li></ul><ul><li>Syntax: CHR(x) </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the character that has the value equivalent to x in the database character set. CHR and ASCII are opposite functions. CHR returns the character given the character number, and ASCII returns the character number given the character. </li></ul><ul><li>Example: </li></ul><ul><li>SELECT CHR(37) a, CHR(100) b, CHR(101) c from dual; </li></ul><ul><li>Output: A B C </li></ul><ul><li>- - - </li></ul><ul><li>% d e </li></ul>
  14. 14. <ul><li>What is DUAL? </li></ul><ul><li>Dual is a small Oracle table created for testing functions or doing quick calculations which has one row and column. Since Oracle’s many functions work on both columns and literals. Some Oracle functions use just literals in these situations DUAL table can be used. </li></ul><ul><li>Structure of Null table: </li></ul><ul><li>Name Null? Type </li></ul><ul><li>----------------------------------------------------- -------- ----------------- </li></ul><ul><li>DUMMY VARCHAR2(1) </li></ul><ul><li>Select * from dual; </li></ul><ul><li>D </li></ul><ul><li>- </li></ul><ul><li>X </li></ul>
  15. 15. <ul><li>CONCAT </li></ul><ul><li>  </li></ul><ul><li>Syntax: CONCAT (String1, String 2) </li></ul><ul><li>  </li></ul><ul><li>Purpose Returns string1 concatenated with string2. This function is identical to the || operator. </li></ul><ul><li>  </li></ul><ul><li>Example: </li></ul><ul><li>  </li></ul><ul><li>SELECT CONCAT(‘Information ’, ‘ Technology’) “Computer” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Computer </li></ul><ul><li>------------- </li></ul><ul><li>Information Technology </li></ul><ul><li>  </li></ul>
  16. 16. <ul><li>INITCAP </li></ul><ul><li>  </li></ul><ul><li>Syntax: INITCAP( String ) </li></ul><ul><li>  </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns string with the first character of each word capitalized and the remaining characters of each word in lowercase. </li></ul></ul><ul><ul><li>Characters that are not letters are unaffected. </li></ul></ul><ul><ul><li>  </li></ul></ul><ul><li>Example: </li></ul><ul><li>  </li></ul><ul><li>SELECT INITCAP (‘time is gold’) “Time” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Speech </li></ul><ul><li>----------------------- </li></ul><ul><li>Time is gold </li></ul>
  17. 17. <ul><li>LOWER </li></ul><ul><li>  </li></ul><ul><li>Syntax: LOWER(String) </li></ul><ul><li>  </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns string with all characters in lowercase. </li></ul></ul><ul><ul><li>Any characters that are not letters will not convert. </li></ul></ul><ul><ul><li>If string has the CHAR datatype, the result is also CHAR. </li></ul></ul><ul><ul><li>If string is VARCHAR2, the result is VARCHAR2. </li></ul></ul><ul><li>  </li></ul><ul><li>Example: </li></ul><ul><li>  </li></ul><ul><li>SELECT LOWER (‘EVERYTHING IN LOWER CASE’) “lower” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: lower </li></ul><ul><li>-------------- </li></ul><ul><li>everything in lower case </li></ul><ul><li>  </li></ul>
  18. 18. <ul><li>UPPER </li></ul><ul><li>  </li></ul><ul><li>Syntax: UPPER(string) </li></ul><ul><li>  </li></ul><ul><li>Purpose </li></ul><ul><ul><li>Returns string with all letters in uppercase. </li></ul></ul><ul><ul><li>If string has datatype CHAR, the return value is also CHAR. </li></ul></ul><ul><ul><li>If string has datatype VARCHAR2, then the return value is VARCHAR2. </li></ul></ul><ul><ul><li>Any Characters that are not letters are left intact in the returned value. </li></ul></ul><ul><li>Example: </li></ul><ul><li>SELECT UPPER (‘print in uppercase’) “UPPER” FROM dual; </li></ul><ul><li>Output: UPPER </li></ul><ul><li>PRINT IN UPPERCASE </li></ul>
  19. 19. <ul><li>LPAD </li></ul><ul><li>Syntax: LPAD(String1, x [,string2]) </li></ul><ul><li>Purpose : </li></ul><ul><ul><li>Returns string1 after padding string2 from left to length x. </li></ul></ul><ul><ul><li>If string2 is less than x characters, it is duplicated as necessary. </li></ul></ul><ul><ul><li>If string2 is more than x characters, only the first required x characters are used. </li></ul></ul><ul><ul><li>If string2 is not specified, it defaults to a single blank for each space. </li></ul></ul><ul><li>Examples: </li></ul><ul><li>SELECT LPAD (‘have a good day’,18) “First” from dual; </li></ul><ul><li>Output: </li></ul><ul><li>First </li></ul><ul><li>----- </li></ul><ul><li>have a good day </li></ul>
  20. 20. <ul><li>SELECT LPAD (‘have a good day’, 20, ‘XY’) “Demo” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Demo </li></ul><ul><li>XYXYXhave a good day </li></ul><ul><li>  </li></ul><ul><li>SELECT LPAD (‘have a good day’, 16, ’XY’) “Test” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Test </li></ul><ul><li>Xhave a good day </li></ul>
  21. 21. <ul><li>RPAD </li></ul><ul><li>  </li></ul><ul><li>Syntax: RPAD(String1,x[,string2]) </li></ul><ul><li>  </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns string1 padded on the right to length x with the characters in string2. </li></ul></ul><ul><ul><li>If string2 is less than x characters, it is duplicated as necessary. </li></ul></ul><ul><ul><li>If string2 is more than x characters, only the first x are used. </li></ul></ul><ul><ul><li>If string2 is not specified, it defaults to a single blank. </li></ul></ul><ul><ul><li>  </li></ul></ul><ul><li>Examples: </li></ul><ul><li>  SELECT RPAD (‘Cricket’, 10, ‘!’) “First” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: First </li></ul><ul><li>---------- </li></ul><ul><li>Cricket!!! </li></ul><ul><li>  </li></ul>
  22. 22. <ul><li>SELECT RPAD(‘Cricket’, 10, ‘AB’) “Second” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Second </li></ul><ul><li>---------- </li></ul><ul><li>CricketABA </li></ul><ul><li>  </li></ul><ul><li>SELECT RPAD ('Cricket', 3) &quot;Third&quot; from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Thi </li></ul><ul><li>--- </li></ul><ul><li>Cri </li></ul>
  23. 23. <ul><li>RTRIM </li></ul><ul><li>  </li></ul><ul><li>Syntax: RTRIM(String1[,string2]) </li></ul><ul><li>  </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns string1 with the rightmost characters appearing in string2 removed. </li></ul></ul><ul><ul><li>String2 defaults to a single blank. </li></ul></ul><ul><ul><li>The database will scan String1, starting from the rightmost position. </li></ul></ul><ul><ul><li>When the first character not in String2 is encountered, the result is returned. </li></ul></ul><ul><li>  Examples: </li></ul><ul><li>SELECT RTRIM(‘This is a string ’) “First” from dual; </li></ul><ul><li>Output: First </li></ul><ul><li> This is a string </li></ul><ul><li>  </li></ul>
  24. 24. <ul><li>SELECT RTRIM(‘This is a stringxxxxx’, ‘x’) “Second” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Second </li></ul><ul><li>---------------- </li></ul><ul><li>This is a string </li></ul><ul><li>  </li></ul><ul><li>SELECT RTRIM(‘This is a string as well’, ‘well’) “Third” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Third </li></ul><ul><li>-------------------- </li></ul><ul><li>This is a string as </li></ul>
  25. 25. <ul><li>TRIM </li></ul><ul><li>This function can used instead of LTRIM and RTRIM </li></ul><ul><li>  </li></ul><ul><li>Example: </li></ul><ul><li>  SELECT TRIM(‘ INDIA ‘) FROM DUAL; </li></ul><ul><li>  </li></ul><ul><li>Output: TRIM( </li></ul><ul><li>----- </li></ul><ul><li>INDIA </li></ul><ul><li>  </li></ul>
  26. 26. <ul><li>REPLACE </li></ul><ul><li>Syntax: </li></ul><ul><li>REPLACE (String, search_str[, replace_str]) </li></ul><ul><li>  </li></ul><ul><li>Purpose : </li></ul><ul><ul><li>Returns string with every occurrence of search_str replaced with replace_str. </li></ul></ul><ul><ul><li>If replace_str is not specified, all occurrences of search_str are removed. </li></ul></ul><ul><li>Examples: </li></ul><ul><li>SELECT REPLACE (‘This and That’, ‘Th’, ‘B’)”First” from dual; </li></ul><ul><li>  Output: First </li></ul><ul><li>Bis and Bat </li></ul><ul><li>  </li></ul>
  27. 27. <ul><li>SELECT REPLACE (‘This and That’, ‘Th’)”Second” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Second </li></ul><ul><li>------------ </li></ul><ul><li>is and at </li></ul><ul><li>  </li></ul><ul><li>SELECT REPLACE (‘This and That’, null) “Third” from dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Third </li></ul><ul><li>------------ </li></ul><ul><li>This and That </li></ul>
  28. 28. <ul><li>SUBSTR </li></ul><ul><li>  Syntax : SUBSTR ( string , a [, b ]) </li></ul><ul><li>  Purpose: </li></ul><ul><ul><li>Returns a portion of string starting at character a, b characters long . </li></ul></ul><ul><ul><li>If a is 0, it is treated as 1(the beginning of the string). </li></ul></ul><ul><ul><li>If b is positive, characters are returned counting from the left. </li></ul></ul><ul><ul><li>If b is negative, characters are returning starting from the end of string, and counting from the right . </li></ul></ul><ul><ul><li>If b is not present, it defaults to the entire string. </li></ul></ul><ul><ul><li>If b is less than 1, NULL is returned. </li></ul></ul><ul><li>Examples: </li></ul><ul><li>SELECT SUBSTR('He is a Good Boy', 2) &quot;First&quot; from dual; </li></ul><ul><li>Output: First </li></ul><ul><li>e is a Good Boy </li></ul><ul><li>SELECT SUBSTR('He is a Good Boy', 2, 4) &quot;Second&quot; from dual </li></ul><ul><li>Output: Second </li></ul><ul><li>e is </li></ul>
  29. 29. <ul><li>SELECT SUBSTR ('He is a Good Boy', -5) &quot;Third&quot; from dual </li></ul><ul><li>  </li></ul><ul><li>Output: Third </li></ul><ul><li>----- </li></ul><ul><li>d Boy </li></ul><ul><li>  </li></ul><ul><li>SELECT SUBSTR ('He is a Good Boy', -5, 3) &quot;Four&quot; from dual </li></ul><ul><li>  </li></ul><ul><li>Output: Fou </li></ul><ul><li>--- </li></ul><ul><li>d B </li></ul>
  30. 30. <ul><li>TRANSLATE </li></ul><ul><li>Syntax: TRANSLATE ( string , from_str , to_str ) </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns string with all occurrences of each character in from_str replaced by the corresponding character in to_str. </li></ul></ul><ul><ul><li>If from_str is longer than to_str, any extra characters in from_str not in to_str are removed from string , since they have no corresponding characters. </li></ul></ul><ul><ul><li>to_str cannot be empty. </li></ul></ul><ul><ul><li>If any argument to TRANSLATE is null, the result is NULL as well. </li></ul></ul><ul><li>  Examples: </li></ul><ul><li>  SELECT TRANSLATE(‘abcdefghij’,’abcdef’,’123456’) from dual; </li></ul><ul><li>  Output: TRANSLATE( </li></ul><ul><li>123456ghij </li></ul><ul><li>SELECT TRANSLATE (‘abcdefghij’, ‘abcdefghij’, ‘123456’) from dual; </li></ul><ul><li>  Output: TRANSL </li></ul><ul><li>123456 </li></ul><ul><li>  </li></ul>
  31. 31. <ul><li>SOUNDEX </li></ul><ul><li>  </li></ul><ul><li>Syntax: Soundex( string ) </li></ul><ul><li>  </li></ul><ul><li>Purpose : </li></ul><ul><li>Returns the phonetic representation of string. This is useful for comparing words that are spelled differently but sound alike. </li></ul><ul><li>Example: </li></ul><ul><li>SELECT ENAME FROM EMP </li></ul><ul><li>WHERE SOUNDEX(ENAME) = SOUNDEX('SMEETH'); </li></ul><ul><li>  </li></ul><ul><li>Output: ENAME </li></ul><ul><li>---------- </li></ul><ul><li>SMITH </li></ul>
  32. 32. Date Functions <ul><li>  The date functions take arguments of type DATE, except for the MONTHS_BETWEEN function, which returns a NUMBER, all of the functions return DATE values. </li></ul><ul><li>  </li></ul>
  33. 33. SYSDATE <ul><li>Syntax: SYSDATE </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the current date and time, of type DATE. </li></ul><ul><li>Takes no arguments. </li></ul><ul><li>When used in distributed SQL statement, SYSDATE returns the date and time of the local database. </li></ul><ul><li>( For instance if the current date is 4th May 2002) </li></ul><ul><li>Example: </li></ul><ul><li> SELECT SYSDATE FROM DUAL; </li></ul><ul><li>Output: SYSDATE </li></ul><ul><li> --------- </li></ul><ul><li> 05-MAY-02 </li></ul>
  34. 34. ADD_MONTHS <ul><li>Syntax: ADD_MONTHS ( d,x ) </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the date d plus x months or d minus x . x can be any integer. </li></ul><ul><li>Example: </li></ul><ul><li>SELECT ADD_MONTHS(‘02-MAR-88’, 3), </li></ul><ul><li>ADD_MONTHS(‘30-JAN- 00’, 1) </li></ul><ul><li>FROM DUAL; </li></ul><ul><li>  Output: </li></ul><ul><li>ADD_MONTH ADD_MONTH </li></ul><ul><li>------------------ ------------ ------ </li></ul><ul><li>02-JUN-88 29-FEB-00 </li></ul>
  35. 35. MONTHS_BETWEEN <ul><li>Syntax: MONTHS_BETWEEN(DATE1,DATE2) </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns the number of months between date1 and date2. </li></ul></ul><ul><ul><li>If both date1 and date2 have the same day component, or if both are the last day of their respective months, then the result is an integer. Otherwise, the result will contain the fractional portion of a 31-day month. </li></ul></ul><ul><li>Example: </li></ul><ul><li>SELECT MONTHS_BETWEEN('12-APR-71', '12-MAR-97') &quot;First&quot;, MONTHS_BETWEEN ('12-APR-71', '12-MAR-60') &quot;Second&quot; FROM dual; </li></ul><ul><li>  Output: First Second </li></ul><ul><li>------- ---------- </li></ul><ul><li> -311 132.67742 </li></ul>
  36. 36. LAST_DAY <ul><li>  Syntax: LAST_DAY( d) </li></ul><ul><li>Purpose: </li></ul><ul><li>Return the date of last day of the month that contains d. This function can be used to determine how many days are left in the current month. </li></ul><ul><li>Example: </li></ul><ul><li>SELECT LAST_DAY('12-APR-71') &quot;CURRENT&quot;, </li></ul><ul><li>LAST_DAY('12-APR-71') - TO_DATE('12-APR-71') </li></ul><ul><li>&quot;Days left&quot; FROM dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Current Days Left </li></ul><ul><li> ------- ---------- </li></ul><ul><li>30-APR-71 18 </li></ul>
  37. 37. NEXT_DAY <ul><li>Syntax: NEXT_DAY(d, string) </li></ul><ul><li>Purpose : </li></ul><ul><li>This function returns the date of next specified day of the week(string) after the d (date). </li></ul><ul><li>Example: </li></ul><ul><li>SELECT NEXT_DAY('07-MAY-02','MONDAY') FROM DUAL; </li></ul><ul><li>Output: NEXT_DAY( </li></ul><ul><li>--------- </li></ul><ul><li>13-MAY-02 </li></ul>
  38. 38. ROUND <ul><li>  </li></ul><ul><li>Syntax: ROUND(d, [, format) </li></ul><ul><li>Purpose : </li></ul><ul><ul><li>Returns the date d to the unit specified by format. </li></ul></ul><ul><ul><li>If format is not specified, it defaults to 'DD', which rounds d to the nearest day. </li></ul></ul><ul><li>Example: </li></ul><ul><li>  SELECT ROUND(TO_DATE(‘12-APR-71’), ‘MM’) &quot;Nearest Month&quot; FROM dual; </li></ul><ul><li>  Output : Nearest Month </li></ul><ul><li>----------------- </li></ul><ul><li>01-APR-71 </li></ul><ul><li>  (1-15 it will round to the same month, 16 and after - next month) </li></ul>
  39. 39. TRUNC   <ul><li>Syntax: TRUNC(d, [,format]) </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>Returns the date d truncated to the unit specified by format. </li></ul></ul><ul><ul><li>If format is not specified, it defaults to 'DD', which truncates d to the nearest day. </li></ul></ul><ul><li>Example: </li></ul><ul><li>SELECT TRUNC( FROM dual; </li></ul><ul><li>  </li></ul><ul><li>Output: First Day </li></ul><ul><li>-------------- </li></ul><ul><li>01-JAN-71 </li></ul>
  40. 40. Date Arithmetic <ul><li>Applying the arithmetic operators to dates and numbers are described. </li></ul><ul><li>When one date value is subtracted from another, the result is a number. </li></ul><ul><li>  Examples of valid date arithmetic expressions follow: </li></ul><ul><li>  </li></ul><ul><li>Example 1: Adding to Date </li></ul><ul><li>  </li></ul><ul><li>SELECT SYSDATE, SYSDATE + 1 &quot;Tomorrow&quot; FROM dual; </li></ul><ul><li>  </li></ul><ul><li>Output: SYSDATE Tomorrow </li></ul><ul><li>-------------- ------------- </li></ul><ul><li>13-NOV-95 14-NOV-95 </li></ul><ul><li>  </li></ul>
  41. 41. Subtracting from Date <ul><li>Example 1: </li></ul><ul><li>SELECT TO_DATE('12-APR-71 12:00:00', 'DD-MON-YY HH24:MI:SS') </li></ul><ul><li>- TO_DATE(15-MAR-71 15:00 -MON-YY HH24:MI:SS') </li></ul><ul><li>&quot;Difference&quot; FROM dual; </li></ul><ul><li>  </li></ul><ul><li>Output: Difference </li></ul><ul><li>-------------- </li></ul><ul><li> 27.875 </li></ul><ul><li>  </li></ul>
  42. 42. <ul><li>Example 2: </li></ul><ul><li>  </li></ul><ul><li>SELECT TO_DATE('10-AUG-98') - TO_DATE('12-FEB-98') FROM DUAL; </li></ul><ul><li>  </li></ul><ul><li>Output: TO_DATE('10-AUG-98')-TO_DATE('12-FEB-98') </li></ul><ul><li>-------------------------------------------------------------- </li></ul><ul><li> 179 </li></ul><ul><li>  </li></ul>
  43. 43. Conversion Functions   <ul><li>TO_NUMBER </li></ul><ul><li>  </li></ul><ul><li>Syntax: </li></ul><ul><li>TO_NUMBER( string [, format [,nlsparams]]) </li></ul><ul><li>  </li></ul><ul><li>Purpose: </li></ul><ul><li> Converts the CHAR or VARCHAR2 string to a NUMBER value. If format is specified, string should correspond to number format. </li></ul><ul><li>Example: </li></ul><ul><li>SELECT TO_NUMBER('25') + TO_NUMBER('50') &quot;TOTAL&quot; FROM DUAL; </li></ul><ul><li>  </li></ul><ul><li>Output: TOTAL </li></ul><ul><li> 75 </li></ul>
  44. 44. TO_CHAR (WITH NUMBERS) <ul><li>  Syntax: </li></ul><ul><li>TO_CHAR( num, [,format[, nlsparams ]]) </li></ul><ul><li>  Purpose: </li></ul><ul><ul><li>Converts the NUMBER argument num to a VARCHAR2. </li></ul></ul><ul><ul><li> If format not specified, the resultant string will have exactly as many characters as necessary to hold the significant digits of num. </li></ul></ul><ul><li>Example: </li></ul><ul><li>SELECT TO_CHAR(123) FROM DUAL; </li></ul><ul><li>  </li></ul><ul><li>Output TO_ </li></ul><ul><li>123 </li></ul>
  45. 45. TO_CHAR (WITH DATE) <ul><li>Syntax: </li></ul><ul><li>TO_CHAR(d,[,format [,nlsparams]]) </li></ul><ul><li>Purpose: </li></ul><ul><ul><li>TO_CHAR can also be used for the conversion of dates values to a specified character format. </li></ul></ul><ul><ul><li>TO_CHAR allows us to format the date in various different ways. </li></ul></ul><ul><li>Example 1: </li></ul><ul><li>SELECT TO_CHAR(SYSDATE, ‘DAY DDSPTH MONTH YEAR') FROM DUAL; </li></ul><ul><li>Output : </li></ul><ul><li>TO_CHAR(SYSDATE,'DAYDDSPTHMONTHYEAR') </li></ul><ul><li>--------------------------------------------------------------------- </li></ul><ul><li>WEDNESDAY FOURTEENTH MARCH TWO THOUSAND ONE </li></ul><ul><li>  </li></ul>
  46. 46. <ul><li>Example 2: </li></ul><ul><li>SELECT TO_CHAR(HIREDATE, 'DDTH MONTH YEAR') &quot;JOINING DATE&quot; </li></ul><ul><li>FROM EMP </li></ul><ul><li>WHERE EMPNO = 7788; </li></ul><ul><li>Output: </li></ul><ul><li>JOINING DATE </li></ul><ul><li>------------------------------------------------- </li></ul><ul><li>09TH DECEMBER TWENTY EIGHTY-TWO </li></ul><ul><li>Example3: </li></ul><ul><li>SELECT TO_CHAR(TO_DATE('14-MAR-01'), 'RM') FROM </li></ul><ul><li>DUAL; </li></ul><ul><li>Output: TO_C </li></ul><ul><li> III </li></ul><ul><li>RM – Roman Numeral Month  </li></ul>
  47. 47. <ul><li>Group / Aggregate Functions </li></ul>
  48. 48. Group / Aggregate Functions <ul><ul><li>Group functions are those statistical functions, which gives information about a group of value taken as whole. </li></ul></ul><ul><ul><li>The aggregate function produce a single value for an entire group or table. </li></ul></ul><ul><ul><li>In all group functions, NULLs are ignored. </li></ul></ul><ul><ul><li>These functions are valid in the select list of a query and the GROUP BY clause only. </li></ul></ul>
  49. 49. <ul><li>AVG </li></ul><ul><li>Syntax: AVG([DISTINCT | ALL]col) </li></ul><ul><li>Purpose: </li></ul><ul><li>Returns the average of the column values. </li></ul><ul><li>  Example: </li></ul><ul><li>  SELECT AVG(sal) FROM EMP; </li></ul>
  50. 50. <ul><li>COUNT </li></ul><ul><li>Syntax : COUNT(*|[DISTINCT |ALL]col) </li></ul><ul><li>Purpose : </li></ul><ul><li>Count function determines the number of rows or non-NULL column values. </li></ul><ul><li> If * is passed, then the total number of rows is returned. </li></ul><ul><li>  </li></ul><ul><li>Example 1: </li></ul><ul><li>SELECT COUNT(*) FROM EMP; </li></ul><ul><li>Example 2: </li></ul><ul><li>  SELECT COUNT(deptno) FROM EMP; </li></ul><ul><li>Example3: </li></ul><ul><li>  SELECT COUNT(DISTINCT deptno) FROM EMP; </li></ul>
  51. 51. <ul><li>MAX </li></ul><ul><li>  Syntax: MAX([DISTINCT | ALL] coL) </li></ul><ul><li>Purpose : </li></ul><ul><li>Returns the maximum value of the select list item. </li></ul><ul><li> </li></ul><ul><li>Example 1: </li></ul><ul><li>SELECT MAX(SAL) FROM EMP; </li></ul><ul><li>Example 2: </li></ul><ul><li>  SELECT MAX(LENGTH(ENAME)) FROM EMP; </li></ul><ul><li>This example returns the length of the longest name in the EMP table: </li></ul>
  52. 52. <ul><li>MIN </li></ul><ul><li>  Syntax : MIN([DISTINCT | ALL] coL) </li></ul><ul><li>  Purpose: Returns the maximum value of the select list item. </li></ul><ul><li>Example: </li></ul><ul><li>SELECT MIN(COMM) “MIN-COMM”, MIN(SAL) “MIN-SAL” FROM EMP; </li></ul><ul><li>  </li></ul><ul><li>Output: MIN-COMM MIN-SAL </li></ul><ul><li>----------------- ------------- </li></ul><ul><li> 0 800 </li></ul>
  53. 53. <ul><li>SUM </li></ul><ul><li>  Syntax : SUM([DISTINCT | ALL] Col) </li></ul><ul><li>  Purpose: Returns the sum of the values for the select list item. </li></ul><ul><li>  </li></ul><ul><li>Example 1:   </li></ul><ul><li>SELECT SUM(SAL) FROM EMP; </li></ul><ul><li>  </li></ul>
  54. 54. <ul><li>Other / General Functions </li></ul><ul><li>DECODE </li></ul><ul><li>Syntax: DECODE( base_expr, compare1, value1, </li></ul><ul><li> compare2, value2, </li></ul><ul><li> . . . </li></ul><ul><li> default ) </li></ul><ul><li>Purpose : </li></ul><ul><ul><li>The DECODE statement is similar to a series of nested IF-THEN-ELSE statements. </li></ul></ul><ul><ul><li>The base_expr is compared to each of compare1, compare2 , etc., in sequence. </li></ul></ul><ul><ul><li>If base_expr matches the i th compare item, the i th value is returned. </li></ul></ul><ul><ul><li>If base_expr doesn't match any of the compare values, default is returned. </li></ul></ul><ul><ul><li>Each compare value is evaluated in turn. </li></ul></ul><ul><ul><li>If a match is found, the remaining compare values, if any, are not evaluated. </li></ul></ul><ul><ul><li>A NULL base_expr is considered equivalent to a NULL compare value. </li></ul></ul><ul><li>  </li></ul>
  55. 55. <ul><li>Example 1: </li></ul><ul><li>  SELECT DECODE(10, 10, 'TEN', 20, 'TWENTY', 30, 'THIRTY') &quot;MATCH&quot; FROM DUAL; </li></ul><ul><li>  </li></ul><ul><li>Output: MAT </li></ul><ul><li>TEN </li></ul><ul><li>  </li></ul>
  56. 56. <ul><li>Example 2: </li></ul><ul><li>  SELECT DECODE(50, 10, ‘TEN’, 20, ‘TWENTY’, 30, ‘THIRTY’, ‘NEW VALUE’) FROM DUAL; </li></ul><ul><li>  </li></ul><ul><li>Output: DECODE(50 </li></ul><ul><li>--------- </li></ul><ul><li>NEW VALUE </li></ul><ul><li>  Example 3: </li></ul><ul><li>  </li></ul><ul><li>SELECT DECODE(NULL, ‘A’, ‘ARUN’, NULL, ‘NOVALUE’, ‘B’, ‘BHARATH’) FROM DUAL; </li></ul><ul><li>  </li></ul><ul><li>Output: DECODE( </li></ul><ul><li>------- </li></ul><ul><li>NOVALUE </li></ul>
  57. 57. <ul><li>GREATEST </li></ul><ul><li>Syntax : GREATEST (expr1[,expr2]…) </li></ul><ul><li>  Purpose : </li></ul><ul><li>Returns the greatest expression of its arguments. </li></ul><ul><li>Each expression is implicitly converted to the type of expr1 before the comparisons are made. </li></ul><ul><li>Example 1: </li></ul><ul><li>  SELECT GREATEST (10, '7', -1) FROM dual; </li></ul><ul><li>  Output: GREATEST (10, '7', -1) </li></ul><ul><li>--------------------- </li></ul><ul><li> 10 </li></ul><ul><li>  Example 2: </li></ul><ul><li>  SELECT GREATEST(‘ASHWIN’, ‘SOFIA’) FROM DUAL; </li></ul><ul><li>  Output: GREAT </li></ul><ul><li>--------- </li></ul><ul><li>SOFIA </li></ul>
  58. 58. <ul><li>LEAST </li></ul><ul><li>  Syntax : LEAST(expr1 [, expr2]…) </li></ul><ul><li>  Purpose : </li></ul><ul><li>This function returns the least value in the list of expressions. LEAST behaves similarly to GREATEST, in that all expressions are implicitly converted to the datatype of the first. </li></ul><ul><li>Example 1: </li></ul><ul><li>  SELECT LEAST (10, '7', -1) FROM dual; </li></ul><ul><li>Output: LEAST(10,'7', -1) </li></ul><ul><li>---------------- </li></ul><ul><li> -1 </li></ul><ul><li>  Example 2: </li></ul><ul><li>  SELECT LEAST ('ASHWIN', 'SOFIA') FROM DUAL; </li></ul><ul><li>  Output: LEAST( </li></ul><ul><li>------ </li></ul><ul><li>ASHWIN </li></ul>
  59. 59. <ul><li>NVL </li></ul><ul><li>Syntax: NVL( expr1, expr2 ) </li></ul><ul><li>Purpose: </li></ul><ul><li>If expr1 is NULL, returns expr2; otherwise, returns expr1. </li></ul><ul><li>The columns with NULL values are ignored in all of the group functions such as sum, Avg etc. </li></ul><ul><li>The NULL function helps in substituting a value in place of a NULL. </li></ul><ul><li>  Example: </li></ul><ul><li>SELECT NVL (null, ‘this is a null value’) “NullTest” FROM DUAL; </li></ul><ul><li>Output : NullTest </li></ul><ul><li> --------------------- </li></ul><ul><li>this is a null value </li></ul><ul><li>  </li></ul><ul><li>SELECT ENAME, SAL, COMM, SAL + COMM “GROSS SAL”, SAL + NVL (COMM, 0) “CORRECT SAL” FROM EMP; </li></ul><ul><li>  (The above command will substitute 0 for commission where the commission is NULL). </li></ul>
  60. 60. <ul><li>UID </li></ul><ul><li>Syntax : UID </li></ul><ul><li>  Purpose : Returns an integer that uniquely identifies the current database user. UID takes no arguments. </li></ul><ul><li>  Example: </li></ul><ul><li>This example shows a sample SQL*Plus session. </li></ul><ul><li>SQL> Connect Scott/Tiger </li></ul><ul><li>Connected. </li></ul><ul><li>SQL> SELECT UID FROM dual; </li></ul><ul><li>UID </li></ul><ul><li>8 </li></ul><ul><li>SQL> connect system/manager </li></ul><ul><li>Connected. </li></ul><ul><li>  SQL> SELECT UID FROM dual; </li></ul><ul><li>UID </li></ul><ul><li>5 </li></ul>
  61. 61. <ul><li>USER </li></ul><ul><li>  Syntax : USER </li></ul><ul><li>  Purpose : Returns a VARCHAR2 value containing the name of the current Oracle user. USER takes no arguments. </li></ul><ul><li>  Example: </li></ul><ul><li>This example shows a sample SQL*PLUS statements </li></ul><ul><li>  SQL> connect Scott/Tiger </li></ul><ul><li>  Connected. </li></ul><ul><li>SQL> SELECT USER FROM dual; </li></ul><ul><li>USER </li></ul><ul><li>SCOTT </li></ul><ul><li>SQL> Connect Sys/Change_on_install </li></ul><ul><li>  Connected. </li></ul><ul><li>SQL> SELECT USER FROM dual; </li></ul><ul><li>USER </li></ul><ul><li>SYS </li></ul>

×