Pergunta

Eu tenho um procedimento armazenado que retorna saída como um cursor ref. Gostaria de armazenar a saída em outra tabela usando a instrução MERGE. Estou tendo problemas no entanto misturando todas as declarações juntos (COM, USANDO, MERGE etc ..).

Assist pode alguém? Obrigado!

Esta é a mesa que eu quero a saída em (Stop_Time é deixado de fora de propósito):

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

Esta é a 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;
Foi útil?

Solução

Eu não acho que você pode resuse o cursor a menos que você escrever um monte de código processual.

Você não pode escrever uma única instrução merge e procedimento queda REPORT_PLAN_AV_USER?

Se você ainda precisa procedimento REPORT_PLAN_AV_USE você pode criar uma exibição que você usar em procedimento REPORT_PLAN_AV_USER e em sua declaração merge (para evitar duplicação de código).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top