Sie sind auf Seite 1von 3

SQL/PLSQL

Q: Difference between Procedure and Function?


Ans:
Functions must return a value whereas Procedures may or may not
Functions can be called from SELECT/UPDATE where procedures cant.
Function takes one input parameter at-least as mandatory whereas
Procedures may take 0 or n number of input parameters.
Q: Difference Between UNION and UNION ALL?
Ans: UNION ALL doesnt eliminate duplicate rows whereas UNION does a select
distinct.
Q: Group BY Clause
Table1 Above:
select count(*)
from Table1
where value='SS'
group by value;
Ans: This will return NULL not ZERO as there are no values as SS in the
table
Q: What is difference between UNIQUE and PRIMARY KEY constraints?
Ans:

A table can have only one PRIMARY KEY whereas there can be any number of
UNIQUE keys.
The columns that compose PK are automatically defined NOT NULL, whereas
a column that compose a UNIQUE is not automatically defined to be
mandatory.
Q: Find the total salary department wise where more than 2 employees
exists.
Xxge_emp_tbl
Emp_ Emp_Na
Id
me
101
Ford

Dept_
No
20

102

Scott

30

103

James

20

104

Harry

40

105

Blake

40

Sal
100
0
200
0
300
0
300
0
300
0

Mgr_Na
me
Shelly
Van
Ford
Morgan
Shelley

106

Jones

40

107

Shelley

60

108

Van

70

500
0
600
0
800
0

Ford
Van
King

Ans:
SELECT dept_no, sum(sal)
FROM xxge_emp_tbl
GROUP BY dept_no
HAVING COUNT(emp_id) > 2;

Q: Get the last record of the above table?


Ans:
SELECT *
FROM xxge_emp_tbl
WHERE ROWID IN (SELECT MAX (ROWID) FROM xxge_emp_tbl);
Q: Get the third highest salary from above table?

SELECT MAX(sal)
FROM
(SELECT DISTINCT sal FROM xxge_emp_tbl ORDER BY sal
)
WHERE rownum < 4
ORDER BY sal ;

Q: Query to get the number of days left in the current month?


Ans:
SELECT SYSDATE,
LAST_DAY (SYSDATE) "Last Date",
LAST_DAY (SYSDATE) - SYSDATE "Days left"
FROM DUAL;
Q: Query to convert number to words?
SELECT TO_CHAR (TO_DATE (543, 'j'), 'jsp') FROM DUAL;
Ans: Five Hundred Forty Three
Q: Write a query to get the employee details whose salary is more than
the average salary of all employees.
Ans:

SELECT emp_id,
emp_name,
dept_no
FROM Xxge_emp_tbl
WHERE sal >
(SELECT AVG(sal) FROM Xxge_emp_tbl
);
Q: Display employees who are IT_prog and salary is greater than 3000 and
department is not equal to
80 and having the manager as 103.
SELECT employee
FROM TABLE name
WHERE salary > 3000
AND dept! = 80
GROUP BY IT_prog
HAVING manager IN (103);
Q: Write a query to display each letter of the word GEDIGITAL in a separate row.
Ans:
SELECT SUBSTR('GEDIGITAL',LEVEL,1) A
FROM DUAL
CONNECT BY LEVEL <=LENGTH('GEDIGITAL');
Q: What message will be displayed upon execution of the below script
declare
l_count number;
begin
select count(1) into l_count from
XXGE_emp_tbl
where emp_name ='Martha';
dbms_output.put_line('Here It Is: ');
exception
when no_data_found
then
dbms_output.put_line('In No Data Found: ');
when others then
dbms_output.put_line('In when Others: ');
end;

Das könnte Ihnen auch gefallen