当前位置:网站首页>Pl/sql basic case
Pl/sql basic case
2022-07-05 22:02:00 【The sea of waves】
PL/SQL Basic case
Case study 1
problem : 1. Count the number of employees employed each year
Their thinking :
Cycle through the number of employees , Take out the entry date of each employee , Compliant , Counter plus 1
Code :
set severoutput on
declare
-- Define cursor
cursor cemp is select to_char(hiredate,'yyyy') from emp;
phiredate varchar2(4);
-- Number of employees hired each year
count80 number :=0;
count81 number :=0;
count82 number :=0;
count87 numner :=0;
begin
-- Open the cursor
open cemp;
loop
-- Take out the year of employment of an employee
fetch cemp into phiredate;
exit when cemp%notfund;
-- Determine the year of employment
if phiredate = '1980' then count80 :=count80+1;
elsif phiredate ='1981' then count81 :=count81+1;
elseif phiredate ='1982' then count82 :=count82+1;
else count87 := count87+1;
end loop;
-- Close the cursor
close cemp;
end;
/
Case study 2
problem :2 Raise wages for employees . From the minimum wage rise, everyone grows 10%, But the total salary should not exceed 5 Ten thousand yuan , Please calculate the number of people who get a raise and the total salary after the raise , And output the number of wage increases and total wages .
Their thinking :
Code :
set serveroutput on
declare
-- Define cursor
cursor cemp is select empno,sal from emp order by sal;
pempno emp.empno%type;
psal emp.sal%type;
-- The number of people who get a raise
countEmp number := 0;
-- The total salary after the increase
salTotal number;
begin
-- Get the initialization value of the total salary
select sum(sal) into salTotal from emp;
-- Open the cursor
open cemp;
loop
--1, The total salary is greater than 5W
exit when salTotal > 5000;
-- Take an employee for a raise
fetch cemp into pempno ,psal;
exit when cemp%notfund;
-- raise
update emp set sal=sal*1.1 when empno=pempno;
-- The number of +1;
countEmp := countEmp+1;
-- The total salary after the increase = The total amount of wages before the increase + sal * 0.1
salTotal :=salTotal + psal * 0.1;
end loop;
-- Close the cursor
close cemp;
commit;
end;
/
Case study 3
problem
Their thinking
Code
set serveroutput on;
declare
-- Define the cursor
cursor cdept is select dno,dname from dep;
pdno dep.dno%type;
pdname dep.dname%type;
-- Define the cursor of grades
cursor cgrade(coursename varchar2,depno number)
is select grade from sc where cno=(select cno from course where cname = coursename)
and sno = (select sno from student where dno = depno);
pgrade sc.grade%type;
-- The number of people in each segment
count1 number,count2 number,count3 number;
-- Selection of each department “ The average score of college physics students ”
avggrade number;
-- Course name
pcourseName varchar2 := " College Physics ";
begin
-- Open the cursor of the system
open cdept;
loop
-- Take the information of a system
fetch cdept into pdno,pdname;
exit when cdept%notfund;
-- Initialization work
count1 := 0; count2 :=0; count3 :=0;
-- The average grade of the Department
select avg(grade) into avggrade from sc where cno =(select cno from course where cname=pcoursename)
and sno in (select sno from student where dno =pdno )
-- Taking the system , The student's grades of College Physics Department
open cgrade(pcourseName,pdno);
loop
-- Take a student's grade
fetch cgrade into pgrade;
exit when cgrade%notfound;
-- Judge the range of achievement
if pgrade < 60 then count1 := count1+1;
elseif pgrade >=60 and pgrade <=85 then count2 :=count2+1;
else count3 := count3 + 1;
end if;
end loop;
close cgrade;
-- Save the current structure
insert into msg1 values(pcourseName,pdno,count1,count2,count3,avggrade);
end loop;
end;
/
There is something wrong , Welcome to the discussion .
Last , Welcome to pay attention to my wechat , What do you like , Collection , Forwarding is my greatest encouragement .
边栏推荐
- 大约SQL现场“这包括”与“包括在”字符串的写法
- Installation of VMware Workstation
- matlab绘制hsv色轮图
- Database recovery strategy
- Summary of El and JSTL precautions
- 微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
- Some common processing problems of structural equation model Amos software
- Implementation technology of recovery
- The American Championship is about to start. Are you ready?
- The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
猜你喜欢
科技云报道:算力网络,还需跨越几道坎?
How can Huawei online match improve the success rate of player matching
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
AD637使用筆記
Exercise 1 simple training of R language drawing
Dbeaver executes multiple insert into error processing at the same time
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
How to use tensorflow2 for cat and dog classification and recognition
Create a virtual machine on VMware (system not installed)
Huawei fast game failed to call the login interface, and returned error code -1
随机推荐
matlab绘制hsv色轮图
How to view Apache log4j 2 remote code execution vulnerability?
Analysis and test of ModbusRTU communication protocol
Multiplexing of Oracle control files
Oracle HugePages没有被使用导致服务器很卡的解决方法
Huawei fast game failed to call the login interface, and returned error code -1
ICMP 介绍
Code bug correction, char is converted to int high-order symbol extension, resulting in changes in positivity and negativity and values. Int num = (int) (unsigned int) a, which will occur in older com
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
Meituan dynamic thread pool practice ideas, open source
Codeforces 12D ball tree array simulation 3 sorting elements
Some common processing problems of structural equation model Amos software
每日刷题记录 (十四)
QML reported an error expected token ";", expected a qualified name ID
Performance monitoring of database tuning solutions
K210 learning notes (IV) k210 runs multiple models at the same time
The American Championship is about to start. Are you ready?
Recovery technology with checkpoints
The solution to the problem that Oracle hugepages are not used, causing the server to be too laggy
C language knowledge points link