0
感謝を表示したり、表示されていない、私はプロジェクトの数を計算手順を記述する必要がありPLSQL新しい給与はアイデアのために、間違った
、および従業員IDが パラメータとして渡され、従業員の 平均労働時間プロシージャに。平均勤務時間が 10未満の場合、従業員の給与は変わりません。そうでない場合は、 が4未満、給与の5%、給与の10%が給与に加算されます。 。
Employee ID: 101 Employee Name: Marlen Number of projects: 3 Average Working Hours: 87 Old Salary: 39206 New Salary: 41166
:ここ
create or replace procedure view_data(p_id number) is
cursor c1
is
select count(distinct a.projectid) as PRJ_COUNT, e.empid, e.empname, e.salary as old_sal, round(avg(a.hours),0)as AVG_HOURS
from assignment a join employee e
on a.empid=e.empid
where e.empid=p_id
group by e.empid,e.empname, e.salary;
creader c1%rowtype;
cursor c2
is
select empid, salary as new_sal
from employee
where empid=p_id for update of salary;
rate_rec c2%rowtype;
v_new_salary number;
begin
--open c1;
--fetch c1 into creader;
for creader in c1 loop
for rate_rec in c2 loop
if creader.avg_hours < 10 then
update employee set salary=rate_rec.new_sal
where empid=rate_rec.empid;
elsif creader.prj_count<4 then
update employee set salary=rate_rec.new_sal+rate_rec.new_sal*0.05
where empid=rate_rec.empid;
else
update employee set salary=rate_rec.new_sal+rate_rec.new_sal*0.1
where empid=rate_rec.empid;
end if;
select salary into v_new_salary from employee
where empid=creader.empid;
dbms_output.put_line('Employee ID: '||creader.empid);
dbms_output.put_line('Employee Name: '||creader.empname);
dbms_output.put_line('Number of projects: '||creader.prj_count);
dbms_output.put_line('Average Working Hours: '||creader.avg_hours);
dbms_output.put_line('Old Salary: '||rate_rec.new_sal);
dbms_output.put_line('New Salary: '||v_new_salary);
end loop;
end loop;
end view_data;
/
が出力されます:PLSQL文で私の出力には表示されません 新しい給与ここ
と間違っ
何かが私のPLSQLプロシージャですカーソルを使用したソリューション:
create or replace procedure view_data(p_id number) is
cursor c1
is
select count(distinct a.projectid) as PRJ_COUNT, e.empid, e.empname, e.salary as old_sal, round(avg(a.hours),0)as AVG_HOURS
from assignment a join employee e
on a.empid=e.empid
where e.empid=p_id
group by e.empid,e.empname, e.salary;
creader c1%rowtype;
cursor c2
is
select empid, salary as new_sal
from employee
where empid=p_id for update of salary;
rate_rec c2%rowtype;
v_new_salary number;
v_bonus number;
begin
for creader in c1 loop
for rate_rec in c2 loop
if creader.avg_hours >= 10 then
if creader.prj_count<4 then
update employee set salary=salary*1.05
where empid=rate_rec.empid
return salary into v_new_salary;
else
update employee set salary=salary*1.1
where empid=rate_rec.empid
returning salary into v_new_salary;
end if;
end if;
v_bonus:=v_new_salary-rate_rec.new_sal;
dbms_output.put_line('Employee ID: '||creader.empid);
dbms_output.put_line('Employee Name: '||creader.empname);
dbms_output.put_line('Number of projects: '||creader.prj_count);
dbms_output.put_line('Average Working Hours: '||creader.avg_hours);
dbms_output.put_line('Old Salary: '||creader.old_sal);
dbms_output.put_line('Bonus: '||v_bonus);
dbms_output.put_line('New Salary: '||v_new_salary);
end loop;
end loop;
end view_data;
/
THX、それはまだ私が新しいカーソル – mydreamadsl
をdiplsayingされます。私は古い給料と新しい給料を表示するコードも追加しました。今それはあなたがしたいことをする必要があります – lkuty
を更新した新旧の給与間違っ – mydreamadsl