DBMS Lab Manual
Activity 5: ( Numeric, character functions)
Use Functions for the following
1. Find the mod of 165,16
2. Find Square Root of 5000
3. Truncate the value 128.3285 to 2 and -1 decimal places
4. Round the value 92.7683 to 2 and -1 decimal places
5. Convert the string ‘Department’ to uppercase and lowercase
6. Display your address convert the first character of each word to uppercase and rest are in
lowercase
7. Combine your first name and last name under the title Full name
8. Take a string length maximum of 15 display your name to the left. The remaining space
should be filled with ‘*’
9. Take a string length maximum of 20 display your name to the right. The remaining space
should be filled with ‘#’
10. Find the length of the string ‘JSS College, Mysore’
11. Display substring ‘BASE’ from ‘DATABASE’
12. Display the position of the first occurrence of character ‘o’ in Position and Length of the
Position
13. Replace string Database with Datatype
14. Display the ASCII value of ‘ ‘ (Space)
15. Display the Character equivalent of 42
Queires:-
1. Find the mod of 165,16
SQL> select mod(165,16) as modulus from dual;
MODULUS
---------
5
2. Find Square Root of 5000
SQL> select sqrt(5000) as square_root from dual;
SQUARE_ROOT
-----------
70.710678
3. Truncate the value 128.3285 to 2 and -1 decimal places
SQL> select trunc(128.3285,2) ,trunc(128.3285,-1) from dual;
TRUNC(128.3285,2) TRUNC(128.3285,-1)
------------------------- ------------------
128.32 120
Priya M R 30
DBMS Lab Manual
4. Round the value 92.7683 to 2 and -1 decimal places
SQL> select round(92.7683 ,2) ,round(92.7683 ,-1) from dual;
ROUND(92.7683,2) ROUND(92.7683,-1)
---------------- -----------------
92.77 90
5. Convert the string ‘Department’ to uppercase and lowercase
SQL> select UPPER('Department') as upper_case, lower('DEPARTMENT') as lower_case
from dual;
UPPER_CASE LOWER_CASE
---------- ----------
DEPARTMENT department
6. Display your address convert the first character of each word to uppercase and rest
are in lowercase
SQL> Select initcap('nie vishweshwara nagar mysore') as address from dual;
ADDRESS
-----------------------------
Nie Vishweshwara Nagar Mysore
7. Combine your first name and last name under the title Full name
SQL> Select concat('nanda','gopalan') as Full_name from dual;
FULL_NAME
------------
Nandagopalan
8. Take a string length maximum of 15 display your name to the left. The remaining
space should be filled with ‘*’
SQL> Select rpad('priyaursmr',15,'*') as rightpadded from dual;
RIGHTPADDED
---------------
priyaursmr*****
Priya M R 31
DBMS Lab Manual
9. Take a string length maximum of 20 display your name to the right. The remaining
space should be filled with ‘#’
SQL> Select lpad('priyaursmr',20,'#') as leftpadded from dual;
LEFTPADDED
---------------
#####priyaursmr
10. Find the length of the string ‘JSS College, Mysore’
SQL> Select length('JSS College, Mysore') as len_str from dual;
LEN_STR
---------
19
11. Display substring ‘BASE’ from ‘DATABASE’
SQL> Select substr('database',5,4) as substring from dual;
SUBS
----
Base
12. Display the position of the first occurrence of character ‘o’ in Position and Length of
the position
SQL> Select instr('Position','o') as position ,length('Position') as length from dual;
POSITION LENGTH
--------- ---------
2 8
13. Replace string Database with Datatype
SQL> Select replace('database','base','type') as replace from dual;
REPLACE
--------
Datatype
14. Display the ASCII value of ‘ ‘ (Space)
SQL> Select ascii(' ') as ascii from dual;
ASCII
---------
32
Priya M R 32
DBMS Lab Manual
15. Display the Character equivalent of 42
SQL> Select CHR(42) as character from dual;
C
-
*
Priya M R 33