我试图在Oracle中执行最基本的存储过程。我只是试图返回由联盟加入的2个查询...代码如下:
CREATE OR REPLACE PROCEDURE GETATMCONTRACTSBYMANAGERID (
MANAGERID IN NUMBER
) AS
BEGIN
select t.ID, t."NUMBER", t.TITLE, t.NOTES, t.CONTRACT_TYPE_ID as CONTRACT_TYPE_ID, t.CONTRACT_STATUS_ID as CONTRACT_STATUS_ID, t.TASK_NUMBER as TASK_NUMBER, c.CONSULTANT_ID,t.TASK_MANAGER_ID, t.IS_COMPREHENSIVE, t."NUMBER", TO_DATE(SUBSTR(t."NUMBER", 8, 2), 'rr') as val, SUBSTR(t."NUMBER", 11, 3) as val2, t.REF_ID from CONTRACT t INNER JOIN CONTRACT c on c.ID = t.REF_ID
where t.TASK_MANAGER_ID = MANAGERID;
UNION
select t.ID, t."NUMBER", t.TITLE, t.NOTES, t.CONTRACT_TYPE_ID as CONTRACT_TYPE_ID, t.CONTRACT_STATUS_ID as CONTRACT_STATUS_ID, t.TASK_NUMBER as TASK_NUMBER, t.CONSULTANT_ID, t.TASK_MANAGER_ID, t.IS_COMPREHENSIVE, t."NUMBER", TO_DATE(SUBSTR(t."NUMBER", 8, 2), 'rr') as val, SUBSTR(t."NUMBER", 11, 3) as val2, t.REF_ID from CONTRACT t
where t."NUMBER" in (select "NUMBER" from Contract t1 where t1.TASK_MANAGER_ID = MANAGERID)
and t.TASK_NUMBER = ' '
order by val desc, val2 desc, TASK_NUMBER asc;
END GETATMCONTRACTSBYMANAGERID;
我将是第一个承认我对SQL Server比使用oracle更舒服的人,但对我而言,它似乎应该有效。
它返回的错误是:
错误(7,1):PLS-00103:遇到符号&#34; UNION&#34;当期望下列之一:(开始情况声明结束异常退出goto如果循环mod空pragma提高返回选择更新,而使用&lt;&lt;继续关闭当前删除获取锁定插入打开回滚保存点设置sql执行提交forall合并管道清除< / p>
非常感谢任何有关此问题的帮助:)
答案 0 :(得分:1)
您在;
运算符之前有一个冗余分号(union
) - 只需删除它:
select t.ID, t."NUMBER", t.TITLE, t.NOTES, t.CONTRACT_TYPE_ID as CONTRACT_TYPE_ID, t.CONTRACT_STATUS_ID as CONTRACT_STATUS_ID, t.TASK_NUMBER as TASK_NUMBER, c.CONSULTANT_ID,t.TASK_MANAGER_ID, t.IS_COMPREHENSIVE, t."NUMBER", TO_DATE(SUBSTR(t."NUMBER", 8, 2), 'rr') as val, SUBSTR(t."NUMBER", 11, 3) as val2, t.REF_ID from CONTRACT t INNER JOIN CONTRACT c on c.ID = t.REF_ID
where t.TASK_MANAGER_ID = MANAGERID -- Semicolon removed here
UNION
select t.ID, t."NUMBER", t.TITLE, t.NOTES, t.CONTRACT_TYPE_ID as CONTRACT_TYPE_ID, t.CONTRACT_STATUS_ID as CONTRACT_STATUS_ID, t.TASK_NUMBER as TASK_NUMBER, t.CONSULTANT_ID, t.TASK_MANAGER_ID, t.IS_COMPREHENSIVE, t."NUMBER", TO_DATE(SUBSTR(t."NUMBER", 8, 2), 'rr') as val, SUBSTR(t."NUMBER", 11, 3) as val2, t.REF_ID from CONTRACT t
where t."NUMBER" in (select "NUMBER" from Contract t1 where t1.TASK_MANAGER_ID = MANAGERID)
and t.TASK_NUMBER = ' '
order by val desc, val2 desc, TASK_NUMBER asc;
答案 1 :(得分:1)
除了半冒号问题,您还需要选择INTO变量来编译代码。