0

我正在执行一个主存储过程以将列加载到目标表中。我有一个名为的列dptname- 该列由不同的项目团队处理,因此他们定义了一个子存储过程,所有要做的就是获得一个 empno 并输出Dptname. 他们要求我们调用下面的存储过程来加载我的dptname专栏。

您能否让我知道如何分配/调用此子存储过程并分配给deptname我的主存储过程中的列?

这是子存储过程的骨架:

get_dptname(in_emp_no, out_dptname)

我的主存储过程:

Create or Replace procedure InsertTargetTable
as
begin
for a in (
Select  EMP.empno
EMP.NAME,
CL.Attendance,
DEPTNAME= "**ASSIGN THE VALUE FROM THE 3rd Party stored procedure**
from EMP, CL
on EMP.empno=CL.empno
) Loop
Insert Into Target Table ( empno, NAME,Attendance, DEPTNAME  ) 
Values (a.empno, a.NAME, a.Attendance, a.DEPTNAME);
ENDLOOP;
COMMIT:
END
4

2 回答 2

0

If the other group created a function GET_DEPT_NAME, then you could use it as follows:

CREATE OR REPLACE PROCEDURE InsertTargetTable
AS
BEGIN

    INSERT INTO Target_Table ( empno, NAME, Attendance, DEPTNAME  ) 
        SELECT EMP.empno, EMP.NAME, CL.Attendance, GET_DEPT_NAME(EMP.empno)
           FROM EMP, CL
           WHERE EMP.empno = CL.empno;

    COMMIT:

END;

A few notes:

  1. The data is being de-normalizing: what if the employee changes departments? Your Target_Table won't be updated but will remain fixed at the department set during insert. Perhaps the department should be looked up when the table is actually queried in order to obtain the current department value.

  2. Hopefully the stored proc is a function, then it can be used easily as shown in the example above. (If not, ask for a function).

  3. Avoid looping if possible. A single "insert into ... select from" statement will be much more efficient.

于 2013-09-03T01:35:13.603 回答
0

您可以使用以下查询。将 DEPT_NO 变量传递给存储过程,因为它是一个 OUT 参数,您可以从主存储过程中访问值。

GET_DPTNAME(IN_EMP_NO=>EMP_NO,OUT_DEPT_NO=>DEPT_NO);
于 2013-09-03T00:44:44.907 回答