Vous êtes sur la page 1sur 8

NIVETHA.R.

S 1041888

4.SQL QUERIES USING BUILT-IN FUNCTIONS


AIM : To write SQL queries using built-in functions. QUERIES :

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

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

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

4. Write a query using built-in function to find the remainder as a result of division

between two numbers.


SQL> select mod(34,7) from dual; MOD(34,7) ---------6

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

6. Write a query using built-in function to find the value of a number m raised to power n.
SQL> select power(5.4,3) from dual; POWER(5.4,3) -----------157.464

7. Write a query using built-in function to find the square root of a number.
SQL> select sqrt(.25) from dual; SQRT(.25) ---------.5

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(32.543) from dual; ROUND(32.543) ------------33

9. Write a query using built-in function to find the exponential of a number.


SQL> select exp(.5) from dual; EXP(.5) ---------1.64872127

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('welcome') from dual; INITCAP ------Welcome

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('welcome'),lower('HOME') from dual; UPPER(' LOWE ------- ---WELCOME home

12. Write a query using built-in function to concatenate two strings.

SQL> select concat('Database','Management') from dual; CONCAT('DATABASE', -----------------DatabaseManagement

13. Write a query using built-in function to find character equivalent of a number.
SQL> select chr(57) from dual; C 9

14. Write a query using built-in function to left pad and right pad a string with *.
SQL> select lpad('Hi',10,'*'),rpad('friend',10,'*') from dual; LPAD('HI', ---------********Hi RPAD('FRIE ---------friend****

15. Write a query using built-in function to perform right and left trim of a string.
SQL> select ltrim(' hey'),rtrim('friend ') from dual;

LTR --hey

RTRIM( -----friend

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

SQL> select substr('chocolate',2,7) from dual; SUBSTR( ------hocolat

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('nivetha','i') from dual; INSTR('NIVETHA','I') -------------------2

18. Write a query using built-in function to find the ascii equivalent of a character given as input.
SQL> select ascii('N') from dual; ASCII('N') ---------78

19. Write a query using built-in function to find the length of a string/ group of string given as input.
SQL> select length('Nandhini') from dual; LENGTH('NANDHINI') -----------------8

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((substr('Thinkyou',1,5)),'i','a') from dual; REPLA ----Thank

21. Write a query using built-in function to replace a particular character in a string by a particular character.
SQL> select replace('head','a','r') from dual; REPL ---herd

22. Write a query using built-in function to find todays date.


SQL> select sysdate from dual; SYSDATE --------03-FEB-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('01-jul-1993',6) from dual; ADD_MONTH --------01-JAN-94

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('03-feb-2012') from dual;

LAST_DAY( --------29-FEB-12

25. Write a query using built-in function to find the number of months between two date.
SQL> select months_between('03-feb-2012','01-jul-2011') from dual; MONTHS_BETWEEN('03-FEB-2012','01-JUL-2011') ------------------------------------------7.06451613

26. Write a query using built-in function to round off a particular date to the next month that follows.
SQL> select round(sysdate,'mon') from dual; ROUND(SYS --------01-FEB-12

27. Write a query using built-in function to round off the date to the nearest Sunday.
SQL> select round(sysdate,'dy')from dual;

ROUND(SYS --------05-FEB-12

RESULT : Hence, the SQL queries are written using Built-in functions.

Vous aimerez peut-être aussi