ORA-06550:第4行,第3列 PLS-00905:对象HR.procempno无效
-我已经尝试过此代码-
create or replace procedure procempno(p_no in number)
IS
v_salary number(10,2);
begin
v_salary:=(select salary from emp where employee_id=p_no);
if v_salary>1000 then
update emp set salary=v_salary*1.75;
else
update emp set salary=5000;
end if;
Exception when no_data_found then
dbms_output.put_line(p_empno||' doesnt exists');
end procempno;
-以下是我最近的代码-
create or replace procedure procempno(p_no in number)
IS
v_salary number(10,2);
begin
select salary into v_salary from emp where employee_id=p_no;
if v_salary>1000 then
update emp set salary=v_salary*1.75 where employee_id=p_no;
else
update emp set salary=5000 where employee_id=p_no;
end if;
Exception when no_data_found then
dbms_output.put_line(p_empno||' doesnt exists');
end procempno;
-使用PLSQL块执行-
declare
v_empno number;
begin
procempno(&v_empno);
end;
让我们考虑一下,empno = 100的工资为25000。 如果输入empno = 100,则检查条件是否为25000> 1000(如果是),则更新薪水=薪水* 1.75。否则更新工资= 5000
答案 0 :(得分:2)
您在第
行有输入错误dbms_output.put_line(p_empno||' doesnt exists');
您应该使用 p_no
dbms_output.put_line(p_no||' doesnt exists');
不要忘记 COMMIT ,并使用良好的代码标准
CREATE OR REPLACE PROCEDURE procempno(p_no IN emp.employee_id%TYPE) IS
v_salary emp.salary%TYPE;
BEGIN
SELECT salary
INTO v_salary
FROM emp
WHERE employee_id = p_no;
IF v_salary > 1000
THEN
UPDATE emp
SET salary = v_salary * 1.75
WHERE employee_id = p_no;
ELSE
UPDATE emp
SET salary = 5000
WHERE employee_id = p_no;
END IF;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line(p_no || ' doesnt exists');
END procempno;
答案 1 :(得分:2)
您可以避免将当前薪水选择到局部变量中并直接更新。对于更漂亮的输出,我确实声明了private func loadUniversity(url: String) {
let configuration = URLSessionConfiguration.ephemeral
let session = URLSession(configuration: configuration)
let url = URL(string: url)!
let task = session.dataTask(with: url) {
(data, response, error) in
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200, let data = data else {
return
}
do {
let decoder = JSONDecoder()
let university = try decoder.decode([UniversityJSON].self, from: data)
for item in university {
self.universityArray.append(University(name: item.university_name.trim()))
}
let queue = OperationQueue.main
queue.addOperation {
self.currentUniversityArray = self.universityArray
print(self.currentUniversityArray)
self.table.reloadData()
}
} catch {
print("Error info: \(error)")
}
}
task.resume()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? UniversityCell else {
return UITableViewCell()
}
cell.name.text = currentUniversityArray[indexPath.row].name
return cell
}
,它将用于显示新的薪水。
这里是一个示例:首先,我将基于Scott的EMP表创建一个临时表(看起来像您的表):
RETVAL
过程:有用的部分是第5-9行,它们可以完成您想要的操作。其余的不必要。
在第12-16行中,我正在检查是否进行了任何更新(例如,拥有SQL> create table t_emp as
2 select empno as employee_id,
3 sal as salary
4 from emp;
Table created.
的员工存在-请注意,在这种情况下,我不需要P_NO
的异常处理程序)。
NO_DATA_FOUND
测试:
SQL> create or replace procedure procempno (p_no in number)
2 is
3 retval t_emp.salary%type;
4 begin
5 update t_emp e set
6 e.salary = case when e.salary > 1000 then e.salary * 1.75
7 else 5000
8 end
9 where e.employee_id = p_no
10 returning e.salary into retval;
11
12 if sql%rowcount = 0 then
13 dbms_output.put_line(p_no || ' does not exist');
14 else
15 dbms_output.put_line('Salary updated to ' || retval);
16 end if;
17 end;
18 /
Procedure created.
SQL>