使用计数的 PL/SQL 更新率
你好,我是 pl/sql 的新手
,我需要将员工人数少于 5 名的所有项目的rate_per_hour 更新为 500 名,
这是我编写的代码,但它会更新所有员工
set serveroutput on
declare
cursor rate_cur is
select * from project
for update of rate_per_hour;
begin
for rate_rec IN rate_cur
loop
update project
set rate_per_hour=500
where current of rate_cur;
end loop;
end;
这是我的表格:
CREATE TABLE employee(
empid number(5),
empname varchar(20),
address varchar(20),
no_of_dependents number(5),
deptno number(5),
CONSTRAINT EMPLOYEE_PKEY PRIMARY KEY(empid),
CONSTRAINT EMPLOYEE_FKEY FOREIGN KEY(deptno) REFERENCES department(deptno));
CREATE TABLE project(
projectno number(5),
location varchar(20),
incharge number(5),
rate_per_hour number(5),
CONSTRAINT PROJECT_PKEY PRIMARY KEY(projectno),
CONSTRAINT PROJECT_FKEY FOREIGN KEY(incharge) REFERENCES employee(empid));
CREATE TABLE assignment(
empid number(5),
projectid number(5),
hours number(5),
CONSTRAINT ASSIGNMENT_FKEY FOREIGN KEY(empid) REFERENCES employee(empid),
CONSTRAINT ASSIGNEMNT_FKEY2 FOREIGN KEY(projectid) REFERENCES project(projectno));
Please suggest a solution
Hi am newbie at pl/sql
I need to update rate_per_hour for all projects having less than 5 employee to 500
here is the code what i wrote, but it updates all employee
set serveroutput on
declare
cursor rate_cur is
select * from project
for update of rate_per_hour;
begin
for rate_rec IN rate_cur
loop
update project
set rate_per_hour=500
where current of rate_cur;
end loop;
end;
Here is my tables:
CREATE TABLE employee(
empid number(5),
empname varchar(20),
address varchar(20),
no_of_dependents number(5),
deptno number(5),
CONSTRAINT EMPLOYEE_PKEY PRIMARY KEY(empid),
CONSTRAINT EMPLOYEE_FKEY FOREIGN KEY(deptno) REFERENCES department(deptno));
CREATE TABLE project(
projectno number(5),
location varchar(20),
incharge number(5),
rate_per_hour number(5),
CONSTRAINT PROJECT_PKEY PRIMARY KEY(projectno),
CONSTRAINT PROJECT_FKEY FOREIGN KEY(incharge) REFERENCES employee(empid));
CREATE TABLE assignment(
empid number(5),
projectid number(5),
hours number(5),
CONSTRAINT ASSIGNMENT_FKEY FOREIGN KEY(empid) REFERENCES employee(empid),
CONSTRAINT ASSIGNEMNT_FKEY2 FOREIGN KEY(projectid) REFERENCES project(projectno));
Please suggest a solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在另一个论坛上找到了帮助!这是代码
I found help on another forums! Here is the code
它会更新所有内容,因为您无限制地选择所有项目。您可以将光标更改为类似以下内容:
It updates all because you are selecting all projects without limit. You can change the cursor to something like: