MERGE将SP的输出光标输出到表中?

时间:2009-07-20 10:16:38

标签: oracle stored-procedures merge-statement

我有一个存储过程,它将输出作为引用游标返回。我想使用MERGE语句将输出存储在另一个表中。我遇到了问题,但将所有语句混合在一起(WITH,USING,MERGE等)。

有人可以协助吗?谢谢!

这是我希望输出的表(STOP_TIME是故意遗漏的):

TABLE: **USER_ALLOCATION**
START_TIME date   NOT NULL Primary Key
USER_ID    number NOT NULL Primary Key
TASK_ID    number NULL

这是SP:

create or replace
PROCEDURE REPORT_PLAN_AV_USER
(
from_dt IN date,
to_dt IN date,
sysur_key IN number,
v_reservations OUT INTRANET_PKG.CURSOR_TYPE
)
IS
BEGIN

OPEN v_reservations FOR

  with  
      MONTHS as (select FROM_DT + ((ROWNUM-1) / (24*2)) as DT from DUAL connect by ROWNUM <= ((TO_DT - FROM_DT) * 24*2) + 1), 
      TIMES as (select DT as START_TIME,(DT + 1/48) as STOP_TIME from MONTHS where TO_NUMBER(TO_CHAR(DT,'HH24')) between 8 and 15 and TO_NUMBER(TO_CHAR(DT,'D')) not in (1,7))
  select 
    TIMES.START_TIME,
    TIMES.STOP_TIME,
    T.TASK_ID,
    sysur_key USER_ID,
  from 
    TIMES 
    left outer join (ALLOCATED_USER u INNER JOIN REQUIRED_RESOURCE r ON u.AU_ID = r.RR_ID INNER JOIN TASK t ON r.TASK_ID = t.TASK_ID)
      ON u.USER_ID = sysur_key AND t.PLAN_TYPE = 3 AND TIMES.start_time >= TRUNC30(t.START_DATE) AND TIMES.start_time < TRUNC30(t.FINISH_DATE)

  where u.USER_ID is null OR u.USER_ID = sysur_key
  order by START_TIME ASC;
END;

1 个答案:

答案 0 :(得分:2)

除非你编写了很多程序代码,否则我认为你不能重新使用游标。

你不能编写单个合并语句并删除程序REPORT_PLAN_AV_USER吗?

如果仍需要过程REPORT_PLAN_AV_USE,则可以创建在过程REPORT_PLAN_AV_USER和merge语句中使用的视图(以防止代码重复)。