0% found this document useful (0 votes)
54 views

0 0+ 0&'4 & $ 00 ' RQ CRQ U ' $ M W 9

155 Technical Aptitude Questions SQL. TRUNCATE table EMP, delete FROM EMP, will the outputs of the above two commanas aiffer? Hence DELETE is a DML command. INSERT INTO commana is useda to Insert the contents of a specifieda file into the specifieda buffer, ana then execute it. IS NULL operator tests column for the absence of aata?

Uploaded by

Satya Prakash
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

0 0+ 0&'4 & $ 00 ' RQ CRQ U ' $ M W 9

155 Technical Aptitude Questions SQL. TRUNCATE table EMP, delete FROM EMP, will the outputs of the above two commanas aiffer? Hence DELETE is a DML command. INSERT INTO commana is useda to Insert the contents of a specifieda file into the specifieda buffer, ana then execute it. IS NULL operator tests column for the absence of aata?

Uploaded by

Satya Prakash
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Technical Aptitude Questions

SQL
1.Which is the subset of SQL commanas usea to manipulate Oracle Database structures,
incluaing tables?
Data DeIinition Language (DDL)
2.What operator performs pattern matching?
LIKE operator
3.What operator tests column for the absence of aata?
IS NULL operator
4.Which commana executes the contents of a specifiea file?
START Iilename~ or Iilename~
5.What is the parameter substitution symbol usea with INSERT INTO commana?
&
6.Which commana aisplays the SQL commana in the SQL buffer, ana then executes it?
RUN
7.What are the wilacaras usea for pattern matching?
Ior single character substitution and Ior multi-character substitution
8.State true or false. EXISTS, SOME, ANY are operators in SQL.
True
9.State true or false. ', ~, all aenote the same operation.
True
10.What are the privileges that can be grantea on a table by a user to others?
Insert, update, delete, select, reIerences, index, execute, alter, all
11.What commana is usea to get back the privileges offerea by the GRANT commana?
REVOKE
12.Which system tables contain information on privileges grantea ana privileges
obtainea?
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
155

Technical Aptitude Questions


USERTABPRIVSMADE, USERTABPRIVSRECD
13.Which system table contains information on constraints on all the tables createa?
USERCONSTRAINTS
14. TRUNCATE TABLE EMP,
DELETE FROM EMP,
Will the outputs of the above two commanas aiffer?
Both will result in deleting all the rows in the table EMP.
15.What is the aifference between TRUNCATE ana DELETE commanas?
TRUNCATE is a DDL command whereas DELETE is a DML command. Hence
DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back.
WHERE clause can be used with DELETE and not with TRUNCATE.
16.What commana is usea to create a table by copying the structure of another table?
Answer :
CREATE TABLE .. AS SELECT command
Explanation :
To copy only the structure, the WHERE clause oI the SELECT command should
contain a FALSE statement as in the Iollowing.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE
WHERE 12;
II the WHERE condition is true, then all the rows or rows satisIying the condition
will be copied to the new table.
17.What will be the output of the following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('' ATHEN '','), '),
AN, **),*,TROUBLE) FROM DUAL,
TROUBLETHETROUBLE
18.What will be the output of the following query?
SELECT DECODE(TRANSLATE(A,1234567890,1111111111), 1,YES, NO ),
Answer :
NO
Explanation :
The query checks whether a given string is a numerical digit.
19.What aoes the following query ao?
SELECT SAL NJL(COMM,0) FROM EMP,
This displays the total salary oI all employees. The null values in the commission
column will be replaced by 0 and added to salary.
20.Which aate function is usea to fina the aifference between two aates?
MONTHSBETWEEN
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
156
Technical Aptitude Questions
21.Why aoes the following commana give a compilation error?
DROP TABLE &TABLENAME,
Variable names should start with an alphabet. Here the table name starts with an
'&' symbol.
22.What is the aavantage of specifying WITH GRANT OPTION in the GRANT
commana?
The privilege receiver can Iurther grant the privileges he/she has obtained Irom
the owner to any other user.
23.What is the use of the DROP option in the ALTER TABLE commana?
It is used to drop constraints speciIied on the table.
24.What is the value of comm ana sal after executing the following query if the initial
value of sal is 10000?
UPDATE EMP SET SAL SAL 1000, COMM SAL*0.1,
sal 11000, comm 1000
25.What is the use of DESC in SQL?
Answer :
DESC has two purposes. It is used to describe a schema as well as to retrieve
rows Irom table in descending order.
Explanation :
The query SELECT * FROM EMP ORDER BY ENAME DESC will display the
output sorted on ENAME in descending order.
26.What is the use of CASCADE CONSTRAINTS?
When this clause is used with the DROP command, a parent table can be dropped
even when a child table exists.
27.Which function is usea to fina the largest integer less than or equal to a specific
value?
FLOOR
28.What is the output of the following query?
SELECT TRUNC(1234.5678,-2) FROM DUAL,
1200
SQL - QUERIES
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
157
Technical Aptitude Questions
I. SCHEMAS
Table 1 . S1UDIES
PNAME (VARCHAR), SPLACE (VARCHAR), COURSE (VARCHAR), CCOST
(NUMBER)
Table 2 . SOF1WARE
PNAME (VARCHAR), TITLE (VARCHAR), DEVIN (VARCHAR), SCOST
(NUMBER), DCOST (NUMBER), SOLD (NUMBER)
Table 3 . PROCRAMMER
PNAME (VARCHAR), DOB (DATE), DOJ (DATE), SEX (CHAR), PROF1
(VARCHAR), PROF2 (VARCHAR), SAL (NUMBER)
LEGEND :
PNAME Programmer Name, SPLACE Study Place, CCOST Course Cost, DEVIN
Developed in, SCOST SoItware Cost, DCOST Development Cost, PROF1
ProIiciency 1
QUERIES :
1. Fina out the selling cost average for packages aevelopea in Oracle.
2. Display the names, ages ana experience of all programmers.
3. Display the names of those who have aone the PGDCA course.
4. What is the highest number of copies sola by a package?
5. Display the names ana aate of birth of all programmers born in April.
6. Display the lowest course fee.
7. How many programmers have aone the DCA course.
8. How much revenue has been earnea through the sale of packages aevelopea in C.
9. Display the aetails of software aevelopea by Rakesh.
10. How many programmers stuaiea at Pentafour.
11. Display the aetails of packages whose sales crossea the 5000 mark.
12. Fina out the number of copies which shoula be sola in oraer to recover the
aevelopment cost of each package.
13. Display the aetails of packages for which the aevelopment cost has been
recoverea.
14. What is the price of costliest software aevelopea in JB?
15. How many packages were aevelopea in Oracle ?
16. How many programmers stuaiea at PRAGATHI?
17. How many programmers paia 10000 to 15000 for the course?
18. What is the average course fee?
19. Display the aetails of programmers knowing C.
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
158
Technical Aptitude Questions
20. How many programmers know either C or Pascal?
21. How many programmers aont know C ana C?
22. How ola is the olaest male programmer?
23. What is the average age of female programmers?
24. Calculate the experience in years for each programmer ana aisplay along with
their names in aescenaing oraer.
25. Who are the programmers who celebrate their birthaays auring the current
month?
26. How many female programmers are there?
27. What are the languages known by the male programmers?
28. What is the average salary?
29. How many people araw 5000 to 7500?
30. Display the aetails of those who aont know C, C or Pascal.
31. Display the costliest package aevelopea by each programmer.
32. Proauce the following output for all the male programmers
Programmer
Mr. Arvina has 15 years of experience
KEYS:
1. SELECT AVG(SCOST) FROM SOFTWARE WHERE DEVIN 'ORACLE';
2. SELECT PNAME,TRUNC(MONTHSBETWEEN(SYSDATE,DOB)/12)
"AGE", TRUNC(MONTHSBETWEEN(SYSDATE,DOJ)/12) "EXPERIENCE"
FROM PROGRAMMER;
3. SELECT PNAME FROM STUDIES WHERE COURSE 'PGDCA';
4. SELECT MAX(SOLD) FROM SOFTWARE;
5. SELECT PNAME, DOB FROM PROGRAMMER WHERE DOB LIKE
'APR';
6. SELECT MIN(CCOST) FROM STUDIES;
7. SELECT COUNT(*) FROM STUDIES WHERE COURSE 'DCA';
8. SELECT SUM(SCOST*SOLD-DCOST) FROM SOFTWARE GROUP BY
DEVIN HAVING DEVIN 'C';
9. SELECT * FROM SOFTWARE WHERE PNAME 'RAKESH';
10. SELECT * FROM STUDIES WHERE SPLACE 'PENTAFOUR';
11. SELECT * FROM SOFTWARE WHERE SCOST*SOLD-DCOST ~ 5000;
12. SELECT CEIL(DCOST/SCOST) FROM SOFTWARE;
13. SELECT * FROM SOFTWARE WHERE SCOST*SOLD ~ DCOST;
14. SELECT MAX(SCOST) FROM SOFTWARE GROUP BY DEVIN HAVING
DEVIN 'VB';
15. SELECT COUNT(*) FROM SOFTWARE WHERE DEVIN 'ORACLE';
16. SELECT COUNT(*) FROM STUDIES WHERE SPLACE 'PRAGATHI';
17. SELECT COUNT(*) FROM STUDIES WHERE CCOST BETWEEN 10000
AND 15000;
18. SELECT AVG(CCOST) FROM STUDIES;
19. SELECT * FROM PROGRAMMER WHERE PROF1 'C' OR PROF2 'C';
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
159
Technical Aptitude Questions
20. SELECT * FROM PROGRAMMER WHERE PROF1 IN ('C','PASCAL') OR
PROF2 IN ('C','PASCAL');
21. SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN ('C','C') AND
PROF2 NOT IN ('C','C');
22. SELECT TRUNC(MAX(MONTHSBETWEEN(SYSDATE,DOB)/12)) FROM
PROGRAMMER WHERE SEX 'M';
23. SELECT TRUNC(AVG(MONTHSBETWEEN(SYSDATE,DOB)/12)) FROM
PROGRAMMER WHERE SEX 'F';
24. SELECT PNAME, TRUNC(MONTHSBETWEEN(SYSDATE,DOJ)/12) FROM
PROGRAMMER ORDER BY PNAME DESC;
25. SELECT PNAME FROM PROGRAMMER WHERE TOCHAR(DOB,'MON')
TOCHAR(SYSDATE,'MON');
26. SELECT COUNT(*) FROM PROGRAMMER WHERE SEX 'F';
27. SELECT DISTINCT(PROF1) FROM PROGRAMMER WHERE SEX 'M';
28. SELECT AVG(SAL) FROM PROGRAMMER;
29. SELECT COUNT(*) FROM PROGRAMMER WHERE SAL BETWEEN 5000
AND 7500;
30. SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN
('C','C','PASCAL') AND PROF2 NOT IN ('C','C','PASCAL');
31. SELECT PNAME,TITLE,SCOST FROM SOFTWARE WHERE SCOST IN
(SELECT MAX(SCOST) FROM SOFTWARE GROUP BY PNAME);
32.SELECT 'Mr.' ,, PNAME ,, ' - has ' ,,
TRUNC(MONTHSBETWEEN(SYSDATE,DOJ)/12) ,, ' years oI experience'
'Programmer FROM PROGRAMMER WHERE SEX 'M' UNION SELECT
'Ms.' ,, PNAME ,, ' - has ' ,, TRUNC (MONTHSBETWEEN
(SYSDATE,DOJ)/12) ,, ' years oI experience' 'Programmer FROM
PROGRAMMER WHERE SEX 'F';
II . SCHEMA :
Table 1 . DEPT
DEPTNO (NOT NULL , NUMBER(2)), DNAME (VARCHAR2(14)),
LOC (VARCHAR2(13)
Table 2 . EMP
EMPNO (NOT NULL , NUMBER(4)), ENAME (VARCHAR2(10)),
JOB (VARCHAR2(9)), MGR (NUMBER(4)), HIREDATE (DATE),
SAL (NUMBER(7,2)), COMM (NUMBER(7,2)), DEPTNO (NUMBER(2))
MGR is the empno oI the employee whom the employee reports to. DEPTNO is a Ioreign
key.
QUERIES
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
160
Technical Aptitude Questions
1.List all the employees who have at least one person reporting to them.
2.List the employee aetails if ana only if more than 10 employees are present in
aepartment no 10.
3.List the name of the employees with their immeaiate higher authority.
4.List all the employees who ao not manage any one.
5.List the employee aetails whose salary is greater than the lowest salary of an employee
belonging to aeptno 20.
6.List the aetails of the employee earning more than the highest paia manager.
7.List the highest salary paia for each fob.
8.Fina the most recently hirea employee in each aepartment.
9.In which year aia most people foin the company? Display the year ana the number of
employees.
10.Which aepartment has the highest annual remuneration bill?
11.Write a query to aisplay a * against the row of the most recently hirea employee.
12.Write a correlatea sub-query to list out the employees who earn more than the
average salary of their aepartment.
13.Fina the nth maximum salary.
14.Select the auplicate recoras (Recoras, which are insertea, that alreaay exist) in the
EMP table.
15.Write a query to list the length of service of the employees (of the form n years ana m
months).
KEYS:
1.SELECT DISTINCT(A.ENAME) FROM EMP A, EMP B WHERE A.EMPNO
B.MGR; or SELECT ENAME FROM EMP WHERE EMPNO IN (SELECT MGR
FROM EMP);
2.SELECT * FROM EMP WHERE DEPTNO IN (SELECT DEPTNO FROM EMP
GROUP BY DEPTNO HAVING COUNT(EMPNO)~10 AND DEPTNO10);
3.SELECT A.ENAME "EMPLOYEE", B.ENAME "REPORTS TO" FROM EMP A,
EMP B WHERE A.MGRB.EMPNO;
4.SELECT * FROM EMP WHERE EMPNO IN ( SELECT EMPNO FROM EMP
MINUS SELECT MGR FROM EMP);
5.SELECT * FROM EMP WHERE SAL ~ ( SELECT MIN(SAL) FROM EMP GROUP
BY DEPTNO HAVING DEPTNO20);
6.SELECT * FROM EMP WHERE SAL ~ ( SELECT MAX(SAL) FROM EMP GROUP
BY JOB HAVING JOB 'MANAGER' );
7.SELECT JOB, MAX(SAL) FROM EMP GROUP BY JOB;
8.SELECT * FROM EMP WHERE (DEPTNO, HIREDATE) IN (SELECT DEPTNO,
MAX(HIREDATE) FROM EMP GROUP BY DEPTNO);
9.SELECT TOCHAR(HIREDATE,'YYYY') "YEAR", COUNT(EMPNO) "NO. OF
EMPLOYEES" FROM EMP GROUP BY TOCHAR(HIREDATE,'YYYY') HAVING
COUNT(EMPNO) (SELECT MAX(COUNT(EMPNO)) FROM EMP GROUP BY
TOCHAR(HIREDATE,'YYYY'));
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
161
Technical Aptitude Questions
10.SELECT DEPTNO, LPAD(SUM(12*(SALNVL(COMM,0))),15)
"COMPENSATION" FROM EMP GROUP BY DEPTNO HAVING SUM(
12*(SALNVL(COMM,0))) (SELECT MAX(SUM(12*(SALNVL(COMM,0))))
FROM EMP GROUP BY DEPTNO);
11.SELECT ENAME, HIREDATE, LPAD('*',8) "RECENTLY HIRED" FROM EMP
WHERE HIREDATE (SELECT MAX(HIREDATE) FROM EMP) UNION SELECT
ENAME NAME, HIREDATE, LPAD(' ',15) "RECENTLY HIRED" FROM EMP
WHERE HIREDATE ! (SELECT MAX(HIREDATE) FROM EMP);
12.SELECT ENAME,SAL FROM EMP E WHERE SAL ~ (SELECT AVG(SAL) FROM
EMP F WHERE E.DEPTNO F.DEPTNO);
13.SELECT ENAME, SAL FROM EMP A WHERE &N (SELECT COUNT
(DISTINCT(SAL)) FROM EMP B WHERE A.SALB.SAL);
14.SELECT * FROM EMP A WHERE A.EMPNO IN (SELECT EMPNO FROM EMP
GROUP BY EMPNO HAVING COUNT(EMPNO)~1) AND A.ROWID!MIN
(ROWID));
15.SELECT ENAME
"EMPLOYEE",TOCHAR(TRUNC(MONTHSBETWEEN(SYSDATE,HIREDATE)/1
2)),,' YEARS ',, TOCHAR(TRUNC(MOD(MONTHSBETWEEN (SYSDATE,
HIREDATE),12))),,' MONTHS ' "LENGTH OF SERVICE" FROM EMP;
Copyright: Vyom Network (http://www.vyomworld.com) - All Rights Reserved
162

You might also like