DBMS 3
DBMS 3
Description : String functions are used to perform an operation on input string and
return an output string. Following are the string functions defined in sql.
1. ASCII(): This function is used to find the ASCII value of a character.
2. CHAR_LENGTH(): Doesn’t work for SQL Server. Use LEN() for SQL Server. This
function is used to find the length of a word.
7. LEFT(): This function is used to SELECT a sub string from the left of given size or
characters.
8. LOCATE(): This function is used to find the nth position of the given word in a string.
9. LOWER(): This function is used to convert the upper case string into lower case.
10. UPPER(): This function is used to convert the lower case string into upper case.
12. RPAD(): This function is used to make the given string as long as the given size by
adding the given symbol on the right.
13. SUBSTR(): This function is used to find a sub string from the a string from the given
position.
14. REPEAT(): This function is used to write the given string again and again till the
number of times mentioned.
Numeric Functions are used to perform operations on numbers and return numbers.
Following are the numeric functions defined in SQL:
1. ABS(): It returns the absolute value of a number.
4. CEIL(): It returns the smallest integer value that is greater than or equal to a number.
5. CEILING(): It returns the smallest integer value that is greater than or equal to a
number.
6. DIV(): It is used for integer division.
7. FLOOR(): It returns the largest integer value that is less than or equal to a number.
From To
DATE VARCHAR2
NUMBER VARCHAR2
Here we see the output of both queries came out to be the same, in spite of the 2nd query
using ‘15000’ as text, it is automatically converted into an int data type.
SELECT first_name,
TO_CHAR (hire_date, 'MONTH DD, YYYY') HIRE_DATE,
TO_CHAR (salary, '$99999.99') Salary
FROM employees
WHERE rownum < 5;
The first TO_CHAR is used to convert the hire date to the date format MONTH DD,
YYYY i.e. month spelled out and padded with spaces, followed by the two-digit day of
the month, and then the four-digit year. If you prefer displaying the month name in mixed
case (that is, "December"), simply use this case in the format argument: ('Month DD,
YYYY').
The second TO_CHAR function in Figure 10-39 is used to format the SALARY to display
the currency sign and two decimal positions.
2. TO_NUMBER function : The TO_NUMBER function converts a character value to
a numeric datatype. If the string being converted contains nonnumeric characters, the
function returns an error.
Syntax:
TO_NUMBER('121.23','9G999D99')
------------------------------
121.23
TO_NUMBER('1210.73','9999.99')
------------------------------
1210.73
3. TO_DATE function : The function takes character values as input and returns
formatted date equivalent of the same. The TO_DATE function allows users to enter a
date in any format, and then it converts the entry into the default format used by Oracle
11g.
Syntax:
TO_DATE('
---------
15-JAN-89