Beruflich Dokumente
Kultur Dokumente
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;
SELECT MAX(sal)
FROM
(SELECT DISTINCT sal FROM xxge_emp_tbl ORDER BY sal
)
WHERE rownum < 4
ORDER BY sal ;
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;