英文:
Oracle PL/SQL: Passing input data from a procedure to a function to insert into a table
问题
I have a package that has one procedure and one function. The procedure gets the name of the employee as an input, and the function should insert it into the employee table.
create or replace package body Emp_Name_pkg is
procedure get_emp_name (p_emp_name VARCHAR(20))
is
....
end get_emp_name;
function insert_emp_name is
insert into Employee (Emp_Name) values p_emp_name;
end insert_emp_name;
end Emp_Name_pkg;
This gives me an error -
PL/SQL: SQL Statement ignored
PL/SQL: ORA-00984: column not allowed here
Errors: check compiler log
Now, even after declaring the p_emp_name in the function, after executing the program, it does not display the value for the employee name in the table.
I am getting the input through a concurrent program, adding the employee name as the parameter there and getting its value through the code but I am not able to do it. The name is not coming up in the table.
How do I get the value for the name from the procedure to the function and eventually insert it in the table since that's my ultimate goal.
And I cannot use insert in the procedure, I HAVE to get input from the procedure and insert using a different function.
英文:
I have a package that has one procedure and one function. The procedure gets the name of the employee as an input and the function should insert it into the employee table.
create or replace package body Emp_Name_pkg is
procedure get_emp_name (p_emp_name VARCHAR(20))
is
....
end get_emp_name;
function insert_emp_name is
insert into Employee (Emp_Name) values p_emp_name;
end insert_emp_name;
end Emp_Name_pkg;
This gives me an error -
PL/SQL: SQL Statement ignored
PL/SQL: ORA-00984: column not allowed here
Errors: check compiler log
Now, even after declaring the p_emp_name in the function, after executing the program, it does not display the value for employee name in the table.
I am getting the input through a concurrent program, adding employee name as the parameter there and getting its value through the code but I am not able to do it. The name is not coming up in the table.
How do I get the value for the name from the procedure to the function and eventually insert it in the table since that's my ultimate goal.
And I cannot use insert in the procedure, I HAVE to get input from procedure and insert using a different function.
答案1
得分: 1
insert_emp_name
应该是一个过程,而不是一个函数。因为无论如何都不会返回结果。
过程 insert_emp_name(p_emp_name varchar2)
is
begin
insert into Employee (Emp_Name) values p_emp_name;
end insert_emp_name;
英文:
insert_emp_name
should be a procedure, not a function. Because no results are being returned anyway.
procedure insert_emp_name(p_emp_name varchar2)
is
begin
insert into Employee (Emp_Name) values p_emp_name;
end insert_emp_name;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论