将Sql Server存储过程迁移到Oracle PL / SQL

时间:2013-04-15 09:15:25

标签: sql-server oracle stored-procedures

以下存储过程适用于SQL Server(在我进行某些特定于oracle的更改之前)。 现在这个存储过程也必须适用于Oracle。

我使用的Oracle Sql Developer在“OPEN CURSOR_ FOR”之后的行中抱怨

不知怎的,甲骨文不喜欢我'组'同时选择语句和联合并在整个结果上做一个命令......

我错了什么?我只对oracle存储过程有所了解......

create or replace
PROCEDURE GetWorkflowStatusForMatrix(
    p_ApplicationId IN varchar2,    
    CURSOR_ OUT sys_refcursor
)
AS
BEGIN   
    OPEN CURSOR_ FOR
    (
  select ApplicationId || ModuleId || UNIT_ID as StatusKey, UNIT_ID, ApplicationId, ModuleId, Owner, "Level", Action, "Comment", LastModifiedUser, LastModifiedDate 
    from WorkflowStatus where ApplicationId = p_ApplicationId

    union

    select distinct e.ApplicationId + WorkflowId + UnitId as StatusKey, UnitId, e.ApplicationId, WorkflowId, w.Owner, 'Level1', 'Working', EventType, UserId, EventDateTime as LastModifiedDate
    from EventLog e
    join WorkflowStatus w on w.ApplicationId = e.ApplicationId and w.ModuleId = e.WorkflowId and w.UNIT_ID = e.UnitId
    where e.ApplicationId = p_ApplicationId and w.Owner <> '' and w.Action = 'Created'
    )
    order by LastModifiedDate DESC;
END;

2 个答案:

答案 0 :(得分:0)

您需要了解如何在Oracle中定义游标 - 这将帮助您解决..

http://www.techonthenet.com/oracle/cursors/declare.php

答案 1 :(得分:0)

create or replace
PROCEDURE GetWorkflowStatusForMatrix(
    p_ApplicationId IN varchar2,    
    CURSOR_ OUT sys_refcursor
)
AS
BEGIN   
  OPEN CURSOR_ FOR
    select ApplicationId || ModuleId || UNIT_ID as StatusKey, UNIT_ID, ApplicationId, ModuleId, Owner, "Level", Action, "Comment", LastModifiedUser, LastModifiedDate 
  from WorkflowStatus where ApplicationId = p_ApplicationId
  union
  select distinct e.ApplicationId + WorkflowId + UnitId as StatusKey, UnitId, e.ApplicationId, WorkflowId, w.Owner, 'Level1', 'Working', EventType, UserId, EventDateTime as LastModifiedDate
from EventLog e
join WorkflowStatus w on w.ApplicationId = e.ApplicationId and w.ModuleId = e.WorkflowId and w.UNIT_ID = e.UnitId
where e.ApplicationId = p_ApplicationId and w.Owner <> '' and w.Action = 'Created'

order by LastModifiedDate DESC;
END;