You are on page 1of 6

SQL- FUNCTIONS-1

By PenchalaRaju.Yanamala

(1).Find out the absolute values of a given number? {ABS (NUM)}

A: - SQL> select ABS (-200) from dual;

(2).Round the numeric values of a given number? {ROUND (NUM)}

A: - SQL> select ROUND (123.5467, 3) from dual;

(3).Truncate the numeric values of a given number? {TRUNC (NUM)}

A: - SQL> select TRUNC (123.5678, 2) from dual;

(4).Round the number to the nearest higher integer, if it has got any
Decimal place? {CEIL (NUM)}

A: - SQL> select CEIL (123.000001) from dual;

(5).Truncate the given number up to all decimal places? {FLOOR (NUM)}

A: - SQL> select FLOOR (123.5678) from dual;

(6).Find out the remainder of the given number? {MOD (NUM)}

A: - SQL> select MOD (9, 2) from dual;

(7).Find out the square root of the given number? {SQRT (NUM)}

A: - SQL> select SQRT (9) from dual;

(8).Find out the Nth power of the given number? {POWER (NUM)}

A: - SQL> select POWER (3, 2) from dual;

(9). Find out the greatest value from the given list of Numbers? {GREATEST
(N)}
A: - SQL> select GREATEST (54, 89, 65) from dual;

(10).find out the least value from the given list of numbers? {LEAST (NUM)}

A: - SQL> select LEAST (54, 89, 65) from dual;

(11).find out the status of the given list of numbers? {SIGN (NUM)}

A: - SQL> select SIGN (-200) from dual;

(12).Replace the null values in the specified column with the Specified
value
List of numbers? {NVL (column n)}
A: - SQL> select NVL (comm, 0) from EMP;

(13).Find the maximum value of the column in the given set of Rows?
{MAX (c n)}
A: - SQL> select MAX (Sal) from EMP;

(14).Find the minimum value of the column in the given set of Rows?
{MIN (c n)}
A: - SQL> select MIN (Sal) from EMP;

(15).Find the total no of column values in the given set of Rows?


{SUM (c n)}
A: - SQL> select SUM (Sal) from EMP;

(16).Find the Average no of column values in the given set of Rows?


{AVG (c n)}
A: - SQL> select AVG (Sal) from EMP;
`
(17).Count the no of rows in the given set of Rows? {COUNT (c n)}

A: - SQL> select COUNT (Sal) from EMP;

(18).Convert the upper case? {UPPER (string)}

A: - SQL> select UPPER (‘oracle’) from Dual;

(19).Convert the lower case? {LOWER (string)}

A: - SQL> select LOWER (‘ORACLE’) from Dual;

(20).Convert the initial letter of each word of the given string


To upper case and rest of the chars to lower case? {INITCAP (St)}

A: - SQL> select INITCAP (‘hello hyd’) from Dual;

(21). Find the ASCII code for the given ASCII Character? {ASCII (St)}

A: - SQL> select ASCII (‘A’) from Dual;

(22).Find the equivalent ASCII character for the given ASCII Code?
{CHR (num)}
A: - SQL> select CHR (65) from Dual;

(23).find the specified part of the string? {SUBSTR (st)}


{SUBSTR (Var2)}
A: - SQL> select SUBSTR (‘MANAGER’, 1, 3) from Dual;

(24).find the position of the specified part of the string? {INSTR (st)}
{INSTR (Var2)}
A: - SQL> select INSTR (‘MANAGER’, ‘A’, 1, 2) from Dual;

(25).find the length of the given string? {LENGTH (st)}


{LENGTH (Var2)}
A: - SQL> select LENGTH (‘ORCCLE’) from Dual;
(26).ADD THE SPECIFIED CHAR(S) TO THE LEFT SIDE OF THE GIVEN
STRING UPTO THE SPECIFIED LENGTH? {LPAD (st)}{LPAD (Var2)}

A: - SQL> select LPAD (‘ORCCLE’, 8,’*’) from Dual;

(27).Add the SPECIFIED CHAR(S) TO THE LEFT SIDE OF THE GIVEN


STRING
UPTO THE SPECIFIED LENGTH? RPAD (st) RPAD (Var2)

A: - SQL> select LPAD (‘ORCCLE’, 8,’*’) from Dual;

(28).Add the SPECIFIED CHAR(S) TO THE RIGHT SIDE OF THE GIVEN


STRING UPTO THE SPECIFIED LENGTH? RPAD (st),RPAD (Var2)
A: - SQL> select RPAD (‘ORCCLE’, 8,’&&’) from Dual;
SQL- FUNCTIONS-3

(29).Remove the specified char(s) from the extreme left side of the
given string LTRIM (st), LTRIM (Var2)

A: - SQL> select LTRIM (‘SMITH’, ‘S’) from Dual;

(30).Remove the specified char(s) from the extreme right side of


the given string RTRIM (st), RTRIM (Var2)

A: - SQL> select RTRIM (‘SMITH’, ‘H’) from Dual;

(31). Join the two strings. CONCAT (st) CONCAT (Var2)

A: - SQL> select CONCAT (‘Mr.’,’JONE’) from Dual;


A: - SQL> select (‘Mr.’||’JONE’) from Dual;

(32).Replace each character of one set with the Corresponding character


of another set in the given string? TRANSLATE (st) TRANSLATE
(Var2)

A: - SQL> select ename, TRANSLATE (ename, ‘ABCDEFGHIJ’,’9876543210’)


from
EMP where ename=’ALLEN’;

(33).Replace set1 completely with set2 in the given string? REPLACE (var2)

A: - SQL> select ename, REPLACE (ename, ‘LL’,’Hello’) from EMP where


ename=’ALLEN’;

(34).Decode acts as a multiple decision-making statement of any


Procedural
language. Like as nested if? DECODE ()

A: - SQL> select JOB, DECODE (JOB, ‘CLERK’,’C’’MANAGER’,’M’, JOB) From


EMP;

(35). Match the char, strings, those spell differently but sounds alike.
SOUNDEX(),SOUNDEX (var2)
A: - SQL> select ename From EMP where soundex (ename) = soundex
(‘SMITH’);

(36). Find the no of months between the given two date values?
MONTHS_BETWEEN(date1, date2)

A: - SQL> select MONTHS_BETWEEN (’01-JAN-03’,’31-DEC-04’) from Dual;

(37).Add the specified no of months to the given date value?ADD_MONTHS


(date,number)

A: - SQL> select ADD_MONTHS (’01-JAN-03’, 4) from Dual;

(38).find the date of ‘day’ (2nd parameter) after the date (1st parameter)?
NEXT_DAY (date, day)
A: - SQL> select NEXT_DAY (’14-JAN-05’,’WED’) from Dual;

(39).find out the most recent date form the given list of date Values?
GREATEST (date1, date2…)
A: - SQL> select GREATEST (’14-JAN-05’, ’14-JAN-03’) from Dual;

(40).find out the oldest date form the given list of date Values? LEAST
(date1, date2…)
A: - SQL> select LEAST (’14-JAN-05’, ’14-JAN-03’) from Dual;

(41).find the operating system date and time. (No parameters are
Required SYSDATE ())

A: - SQL> select SYSDATE from Dual;

(42).Converts any date value to a char value in the specified Format as well
as to convert number into character? TO_CHAR (date)

A: - SQL> select TO_CHAR (’SYSDATE, DD/MONTH/YYYY’) from Dual;

(43).It converts character string into date value. TO_DATE (CHAR)

A: - SQL> select TO_DATE (’09022000’,’DDMMYYYY’) from Dual;

44. TO_NUMBER ()

45. HEXTORAW ()

46. RAWTOHEX ()

47. CHARTOROWID ()

48. ROWIDTOCHAR ()

49. Display the names of the employees in Uppercase?


SQL>select upper(ename)from emp;

50. Display the names of the employees in Lowercase?


SQL>select lower(ename)from emp;

51. Display the names of the employees in Propercase?


SQL>select initcap(ename)from emp;

52. Display the length of Your name using appropriate function?


SQL>select length('name') from dual;

53. Display the length of all the employee names?


SQL>select length(ename) from emp;

54. select name of the employee concatenate with employee number?


SQL>select ename||empno from emp;

55. User appropriate function and extract 3 characters starting from 2


characters from the following string 'Oracle'. i.e the out put should be
'ac'?
SQL>select substr('oracle',3,2) from dual;

56. Find the First occurance of character 'a' from the following string i.e
'Computer Maintenance Corporation'?
SQL>SELECT INSTR('Computer Maintenance Corporation','a',1) FROM DUAL;

57. Display the total number of employee working in the company?


SQL>select count(*) from emp;

58. Display the total salary beiging paid to all employees?


SQL>select sum(sal) from emp;

59. Display the maximum salary from emp table?


SQL>select max(sal) from emp;

60. Display the minimum salary from emp table?


SQL>select min(sal) from emp;

61. Display the average salary from emp table?


SQL>select avg(sal) from emp;

62. Display the maximum salary being paid to CLERK?


SQL>select max(sal) from emp where job='CLERK';

63. Display the maximum salary being paid to depart number 20?
SQL>select max(sal) from emp where deptno=20;

64. Display the minimum salary being paid to any SALESMAN?


SQL>select min(sal) from emp where job='SALESMAN';

65. Display the average salary drawn by MANAGERS?


SQL>select avg(sal) from emp where job='MANAGER';

66. Display the total salary drawn by ANALYST working in depart


number40?
SQL>select sum(sal) from emp where job='ANALYST' and deptno=40;

67. Replace every occurance of alphabhet A with B in the string Allens(use


translate function)?
SQL>select translate('Allens','A','B') from dual;
68. Display the informaction from emp table.Where job manager is found it
should be displayed as boos(Use replace function)?
SQL>select replace(JOB,'MANAGER','BOSS') FROM EMP;

69. Display empno,ename,deptno from emp table.Instead of display


department numbers display the related department name(Use decode
function)?
SQL>select
empno,ename,decode(deptno,10,'ACCOUNTING',20,'RESEARCH',30,
'SALES',40,'OPRATIONS') from emp;

70. Display the following output for each row from emp table?
“scott has joined the company on wednesday 13th August ninten ninety”
SQL>select ENAME||' HAS JOINED THE COMPANY ON '||
to_char(HIREDATE,'day
ddth Month year') from EMP;

71. Display the common jobs from department number 10 and 20?
SQL>select job from emp where deptno=10 and job in(select job from emp
where deptno=20);

You might also like