You are on page 1of 6

Ex.

No: 4

SQL Queries using Built-in Functions

1. Write a query using built-in function to round-off a number to nearest whole Number
SQL> select round(7.899,-1) from dual; ROUND(7.899,-1) --------------10

2. Write a query using built-in function to find the absolute value of a number.
SQL> select abs(-9.8) from dual; ABS(-9.8) ---------9.8

3. Write a query using built-in function to retain the decimal part and truncate the fractional part in a number.
SQL> select trunc(7.4678) from dual; TRUNC(7.4678) ------------7

4. Write a query using built-in function to find the remainder as a result of division between two numbers.
SQL> select mod(650,67) from dual; MOD(650,67) ----------47

5. Write a query using built-in function to find the sign of a value without its magnitude.
SQL> select sign(-4) from dual; SIGN(-4) ----------1

6. Write a query using built-in function to find the value of a number m raised to power n. SQL> select power(7,3) from dual; POWER(7,3) ---------343 7. Write a query using built-in function to find the square root of a number. SQL> select sqrt(441) from dual; SQRT(441) ---------21 8. Write a query using built-in function to round off a number to the nearest integer with respect to the decimal places. SQL> select round(7.899,0) from dual; ROUND(7.899,0) -------------8 9. Write a query using built-in function to find the exponential of a number. SQL> select exp(5) from dual; EXP(5) ---------148.413159 10. Write a query using built-in function to accept a character/ column of characters as input and return as output the initial character in uppercase. SQL> select initcap('yamini') from dual; INITCA -----Yamini

11. Write a query using built-in function to accept a character/ column of characters as input and return as output in uppercase and lowercase. SQL> select upper('hello'),lower('HELLO') FROM DUAL; UPPER LOWER --------HELLO hello 12. Write a query using built-in function to concatenate two strings. SQL> select concat('hello','world')FROM DUAL; CONCAT('HE ---------helloworld 13. Write a query using built-in function to find character equivalent of a number. SQL> select chr(87) from dual; C W 14. Write a query using built-in function to left pad and right pad a string with *. SQL> select lpad('database',12,'*'),rpad('manage',10,'*') from dual; LPAD('DATABA RPAD('MANA --------------------****database manage**** 15. Write a query using built-in function to perform right and left trim of a string. SQL> select ltrim(' data'),rtrim('base ') from dual; LTRI RTRI ---- ---data base

16. Write a query using built-in function to extract specified number of characters from a string.

SQL> select substr('yamini',5,3) from dual; SU -ni 17. Write a query using built-in function to return the length of a string up to the first occurrence of the character specified. SQL> select instr('ranjani','n') from dual; INSTR('RANJANI','N') -------------------3 18. Write a query using built-in function to find the ascii equivalent of a character given as input. SQL> select ascii('H') from dual; ASCII('H') ---------72 19. Write a query using built-in function to find the length of a string/ group of string given as input. SQL> select length('yamini') from dual; LENGTH('YAMINI') ---------------6 20. Write a query using built-in function to extract specified number of characters and replace with new characters from specified string. SQL> select replace('roadrash','sh','ce') from dual; REPLACE( -------roadrace

21. Write a query using built-in function to replace a particular character in a string by a particular character.

SQL> select replace('cane','c','l') from dual; REPL ---lane 22. Write a query using built-in function to find todays date. SQL> select sysdate from dual; SYSDATE --------22-JAN-12 23. Write a query using built-in function to increase a particular/ group of date by number of months specified. SQL> select add_months(sysdate,2) from dual; ADD_MONTH --------23-MAR-12 24. Write a query using built-in function to find the last date of the month in the particular date specified. SQL> select last_day(sysdate) from dual; LAST_DAY( --------31-JAN-12 25. Write a query using built-in function to find the number of months between two date. SQL> select months_between('21-jun-13','21-nov-11') from dual; MONTHS_BETWEEN('21-JUN-13','21-NOV-11') --------------------------------------19 26. Write a query using built-in function to round off a particular date to the next month that follows. SQL> select round(to_date('25-jun-12'),'month') from dual;

ROUND(TO_ --------01-JUL-12 27. Write a query using built-in function to round off the date to the nearest Sunday. SQL> select round(to_date(sysdate),'day') from dual; ROUND(TO_ --------12-FEB-12

You might also like