ORACLE database exercises
Use the emp table under the scott/tiger user to complete the following exercises. The structure of the table is explained as follows
emp employee table field content is as follows:
empno employee number
ename Employee name
job work
mgr Superior number
hiredate Date hired
sal salary
comm Commission
deptno department number
1.Select all employees in department 30.
2. List the names, numbers and department numbers of all clerks (CLERK).
3. Find employees whose commissions are higher than their salaries.
4. Find employees whose commission is higher than 60% of their salary.
5. Find the detailed information of all managers (MANAGER) in department 10 and all clerks (CLERK) in department 20.
6. Find the detailed information of all managers (MANAGER) in department 10, all clerks (CLERK) in department 20, and all employees who are neither managers nor clerks but whose salary is greater than or equal to 2000.
7. Find out the different jobs of employees who work on commission.
8. Find employees who charge no commission or charge less than 100 commission.
9. Find all employees employed on the third to last day of each month.
10. Find employees who were hired more than 12 years ago.
11. Display the names of all employees with initial capital letters.
12. Display the name of the employee with exactly 5 characters.
13.Display the names of employees without "R".
14.Display the first three characters of all employees’ names.
15. Display the names of all employees and replace all "A" with a
16. Display the names and dates of employment of employees with more than 10 years of service.
17. Display employee details, sorted by name.
18. Display the names and dates of employment of employees, ranking the oldest employees first based on their years of service.
19. Display the names, jobs and salaries of all employees, sorted by job in descending order, or by salary if the jobs are the same.
20. Display the names of all employees, the year and month they joined the company, sorted by the month of employment date, if the months are the same, the employees with the earliest year will be sorted first.
21. Display the daily salary of all employees when a month is 30 days, ignoring the remainder.
22. Find all employees hired in February (of any year).
23.For each employee, display the number of days since he joined the company.
24. Display the names of all employees whose name field contains "A" anywhere.
25. Display the service years of all employees in the form of year, month and day. (Approximately)
oracle question
(1) select deptno from dept where depptno in (select deptno from em);
(2)select empno,ename,sal from em where sal>(select sal from em where ename = 'SMITH');
(3)SELECT e.ename,d.dname from em e,dept d where e.deptno=d.deptno and e.job = 'CLERK';
(4)select empno,ename from em where job in (select job from em where ename = 'SCOTT') ;
(5)select job,min(sal) from em group by job;
(6)select d.dname ,min(e.sal) from dept d,em e
where d.deptno=e.deptno and e.job ='MANAGER' group by d.dname;
Oracle 11G SQL practice homework questions
7.select employee name, salary from table where salary 8.select employee name, salary from table where salary>avg (salary) order by position;
9. Example: The number of column n in t1 is [2,3]; the number of column n in t2 is [1,2,3,4]
select * from t2 where n >any(select n from t1); Result: 3,4.
Note: Query which of the numbers in column n in table t2 is the largest number [including max] than the number in column n in table t1.
select * from t2 where n = any(select n from t1); Result: 2,3.
select * from t2 where n 10.select * from t2 where n >all(select n from t1); Result: 4.
select * from t2 where n 12.SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2; merge table_name1 and table_name2 tables without duplicate columns.
SELECT column_name(s) FROM table_name1 UNION ALL SELECT column_name(s) FROM table_name2; Connect all the data in the two tables table_name1 and table_name2, there are duplicates.
An oracle stored procedure problem solution
CREATE TABLE SC(
SNO INT,
CNO varchar(10),
GRADE INT
);
INSERT INTO SC VALUES(95001, 'Math', 75);
INSERT INTO SC VALUES(95001, '中文', 92);
INSERT INTO SC VALUES(95002, 'English', 64);
INSERT INTO SC VALUES(95002, 'English', 77);
INSERT INTO SC VALUES(95003, 'Math', 85);
CREATE TABLE SC_TOTAL(
SNO INT PRIMARY KEY,
"Mathematics" number(5,2),
"Chinese" number(5,2),
"English" number(5,2),
"Average score" number(5,2)
);
DECLARE
v_row_count INT;
BEGIN
FOR sc_rec IN (SELECT * FROM SC)
LOOP
-- Determine whether the data has
SELECT COUNT(*) INTO v_row_count
FROM SC_TOTAL
WHERE SNO = sc_rec.SNO;
IF v_row_count = 0 THEN
-- The data does not exist. Insert first.
INSERT INTO SC_TOTAL(SNO) VALUES (sc_rec.SNO);
END IF;
-- Based on the course, update specific columns.
IF sc_rec.CNO = 'Mathematics' THEN
UPDATE SC_TOTAL SET "MATH" = sc_rec.GRADE WHERE SNO = sc_rec.SNO;
ELSIF sc_rec.CNO = 'Chinese' THEN
UPDATE SC_TOTAL SET "中文" = sc_rec.GRADE WHERE SNO = sc_rec.SNO;
ELSIF sc_rec.CNO = 'English' THEN
UPDATE SC_TOTAL SET "English" = sc_rec.GRADE WHERE SNO = sc_rec.SNO;
END IF;
-- Calculate the average score.
UPDATE SC_TOTAL
SET "Average score" = (NVL ("Mathematics", 0) NVL ("Chinese", 0) NVL ("English", 0))
/ (NVL2 ("Mathematics", 1,0) NVL2 ("Chinese", 1, 0) NVL2 ("English", 1, 0))
WHERE SNO = sc_rec.SNO;
END LOOP;
END;
/
-- Data verification.
SQL>SELECT * FROM SC_TOTAL;
SNO Mathematics Chinese English Average Score
---------- ---------- ---------- ---------- ------- ---
95001 75 92 83.5
95002 77 77
95003 85 85
The above is the detailed content of Practice ORACLE database questions. For more information, please follow other related articles on the PHP Chinese website!

What’s the difference between Linux and Mac? Do you want to install Linux on Mac? This post from php.cn will show you all. You can refer to this guide to dual boot Linux and macOS.

What is MHTML? How to open or view it? What are the differences between it and HTML? How to convert MHTML to HTML? If you are looking for the answers to the above questions, you can refer to this post from php.cn.

This article focuses on the topic that deleted files keep reappearing in Windows 10, introducing the responsible reasons and feasible solutions.

This post teaches you how to deactivate Windows 10/11 by removing product key or license. You can use that product key to activate another computer later if you want. For more computer tips and tricks, you can visit php.cn Software official website.

Some Windows users report that they are prompted by the error 0164 memory size decreased screen every time they boot the computer. What’s wrong with it? If you are in the same boat, congratulations! You’ve come to the right place! In this post from p

This Page Isn’t Available Right Now is an error message you may encounter when you visit Facebook using your web browser. In this php.cn post, we will list some effective methods you can try to get rid of this error.

Windows 11 KB5010414, a new optional update for Windows 11, is available now. Do you know what’s new and fixes in it? php.cn Software will show you this information in this post. Besides, it also tells you how to download and install it on your compu

Want to pause Windows Update on your Windows 11 computer? Want to set active hours to arrange a computer restart to complete the update process? You need to know how to change Windows Update settings in Windows 11. This php.cn post will show you the


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
