Oracle PL/SQL:将输入数据从过程传递到函数以插入到表中。

huangapple go评论57阅读模式
英文:

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;

huangapple
  • 本文由 发表于 2023年5月29日 16:46:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355859.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定