将我的SQL Server存储过程转换为Oracle存储过程会引发一些错误:
错误(13,10):PLS-00428:此SELECT语句中需要INTO子句
错误(36,13):PLS-00428:此SELECT语句中需要INTO子句
错误(59,16):PLS-00428:此SELECT语句中需要INTO子句
SQL Server存储过程:
CREATE PROCEDURE [dbo].[proname]
@pdate DATE,
@p1 VARCHAR(10),
@p2 INT
AS
BEGIN
SET NOCOUNT ON;
IF @p1 = 'District'
SELECT
ROW_NUMBER() OVER (ORDER BY DueDateUnformatted ASC) AS id,
ActivityName, ActivityKey,
WorkType,
DueDateUnformatted AS DueDate,
Priority, ComplianceDate, AssignmentName,
COUNT(EventKey) AS Total
FROM
dbo.view1
WHERE
DueDateUnformatted < DATEADD(DAY, 1, pdate)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND DistrictKey = @p2
GROUP BY
ActivityName, ActivityKey, WorkType, DueDateUnformatted,
Priority, ComplianceDate, AssignmentName
ELSE IF @p1 = 'Division'
SELECT
ROW_NUMBER() OVER (ORDER BY DueDateUnformatted ASC) AS id,
ActivityName, ActivityKey,
WorkType,
DueDateUnformatted AS DueDate,
Priority, ComplianceDate, AssignmentName,
COUNT(EventKey) AS Total
FROM
dbo.view1
WHERE
DueDateUnformatted < DATEADD(DAY, 1, pdate)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND DistrictKey = @p2
GROUP BY
ActivityName, ActivityKey, WorkType, DueDateUnformatted,
Priority, ComplianceDate, AssignmentName
ELSE IF @p1 = 'Company'
SELECT
ROW_NUMBER() OVER (ORDER BY DueDateUnformatted ASC) AS id,
ActivityKey,
WorkType,
DueDateUnformatted AS DueDate,
Priority, ComplianceDate, AssignmentName,
COUNT(EventKey) AS Total
FROM
dbo.view1
WHERE
DueDateUnformatted < DATEADD(DAY, 1, pdate)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND CompanyKey = @p2
GROUP BY
ActivityName, ActivityKey, WorkType, DueDateUnformatted,
Priority, ComplianceDate, AssignmentName
END
转换Oracle存储过程:
CREATE OR REPLACE PROCEDURE procname
(
pdate VARCHAR2,
p2 VARCHAR2,
p3 NUMBER
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
IF p2 = 'District' THEN
SELECT ROW_NUMBER() OVER ( ORDER BY DueDateUnformatted ASC ) id,
ActivityName ,
ActivityKey ,
WorkType ,
DueDateUnformatted DueDate ,
Priority ,
COUNT(EventKey) Total
FROM view1
WHERE DueDateUnformatted < (TO_DATE(pdate)+1) --utils.dateadd('DAY', 1, v_end_date)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND DistrictKey = p3
GROUP BY ActivityName,ActivityKey,WorkType,DueDateUnformatted,Priority;
ELSE
IF p2 = 'Division' THEN
SELECT ROW_NUMBER() OVER ( ORDER BY DueDateUnformatted ASC ) id ,
ActivityName ,
ActivityKey ,
WorkType ,
DueDateUnformatted DueDate ,
Priority ,
COUNT(EventKey) Total
FROM view1
WHERE DueDateUnformatted < (TO_DATE(pdate)+1)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND DivisionKey = p3
GROUP BY ActivityName,ActivityKey,WorkType,DueDateUnformatted,Priority;
ELSE
IF p2 = 'Company' THEN
SELECT ROW_NUMBER() OVER ( ORDER BY DueDateUnformatted ASC ) id ,
ActivityName ,
ActivityKey ,
WorkType ,
DueDateUnformatted DueDate ,
Priority ,
COUNT(EventKey) Total
FROM view1
WHERE DueDateUnformatted < (TO_DATE(pdate)+1)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND CompanyKey = p3
GROUP BY ActivityName,ActivityKey,WorkType,DueDateUnformatted,Priority;
END IF;
END IF;
END IF;
END;
答案 0 :(得分:0)
您在所有INTO
语句中都缺少SELECT
子句。为此,您应首先声明将接受您选择的值的变量。在我的示例中,我声明了两个NUMBER数据类型变量(将接受ROW_NUMBER和COUNT函数的结果),而其他采用相应视图列的数据类型(这就是我使用column%type
的原因语法)。
请注意,WHERE子句必须确保每个SELECT
最多返回一行,否则您将获得TOO-MANY-ROWS
(而如果它不返回任何内容,则为'我必须处理NO-DATA-FOUND
)。
我为过程的参数添加了IN
关键字。这是默认设置,但是 - 如果你真的使用它 - 毫无疑问你打算用它们做什么。
以下代码至少应该编译。虽然,整个代码都值得怀疑,因为你确实选择了一些值,但以后什么都不做。
CREATE OR REPLACE PROCEDURE procname (pdate IN VARCHAR2, p2 IN VARCHAR2, p3 IN NUMBER)
AS
l_id NUMBER; -- it is ROW_NUMBER
l_activityname view1.activityname%TYPE;
l_activitykey view1.activitykey%TYPE;
l_worktype view1.worktype%TYPE;
l_duedate view1.duedateunformatted%TYPE;
l_priority view1.priority%TYPE;
l_total NUMBER; -- it is COUNT
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
IF p2 = 'District'
THEN
SELECT ROW_NUMBER () OVER (ORDER BY DueDateUnformatted ASC) id,
ActivityName,
ActivityKey,
WorkType,
DueDateUnformatted DueDate,
Priority,
COUNT (EventKey) Total
INTO l_id,
l_activityname,
l_activitykey,
l_worktype,
l_duedate,
l_priority,
l_total
FROM view1
WHERE DueDateUnformatted < (TO_DATE (pdate) + 1) --utils.dateadd('DAY', 1, v_end_date)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND DistrictKey = p3
GROUP BY ActivityName,
ActivityKey,
WorkType,
DueDateUnformatted,
Priority;
ELSE
IF p2 = 'Division'
THEN
SELECT ROW_NUMBER () OVER (ORDER BY DueDateUnformatted ASC) id,
ActivityName,
ActivityKey,
WorkType,
DueDateUnformatted DueDate,
Priority,
COUNT (EventKey) Total
INTO l_id,
l_activityname,
l_activitykey,
l_worktype,
l_duedate,
l_priority,
l_total
FROM view1
WHERE DueDateUnformatted < (TO_DATE (pdate) + 1)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND DivisionKey = p3
GROUP BY ActivityName,
ActivityKey,
WorkType,
DueDateUnformatted,
Priority;
ELSE
IF p2 = 'Company'
THEN
SELECT ROW_NUMBER () OVER (ORDER BY DueDateUnformatted ASC) id,
ActivityName,
ActivityKey,
WorkType,
DueDateUnformatted DueDate,
Priority,
COUNT (EventKey) Total
INTO l_id,
l_activityname,
l_activitykey,
l_worktype,
l_duedate,
l_priority,
l_total
FROM view1
WHERE DueDateUnformatted < (TO_DATE (pdate) + 1)
AND parentEventKey IS NULL
AND inspectiondate IS NULL
AND CompanyKey = p3
GROUP BY ActivityName,
ActivityKey,
WorkType,
DueDateUnformatted,
Priority;
END IF;
END IF;
END IF;
END;