2013-12-17 62 views
0

我已经努力了,但没有得到solutin谴责sp下面.. plz帮助!努力解决错误1064

CREATE PROCEDURE AccountLedgerViewUnderBank() 

begin 


WITH GroupInMainGroup (accountGroupId,HierarchyLevel) AS 
(
select accountGroupId, 
1 as HierarchyLevel 
from tbl_AccountGroup where accountGroupId='9' 
UNION ALL 
select e.accountGroupId, 
G.HierarchyLevel + 1 AS HierarchyLevel 
from tbl_AccountGroup as e,GroupInMainGroup G 
where e.groupUnder=G.accountGroupId 

) 
SELECT 
ledgerId AS 'Account Ledger Id', 
acccountLedgerName AS 'Account Ledger Name' 
FROM tbl_AccountLedger 

where accountGroupId IN (select accountGroupId from GroupInMainGroup 
) 
end ; // 

显示

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'Group 
InMainGroup (accountGroupId,HierarchyLevel) AS 
(
select accountGroupId, 
1 a' at line 6 
+3

MySQL不支持公共表表达式。您需要升级到允许它们的DBMS。 –

回答

2

它看起来就像你试图用一个CTE,这是不符合MySQL的支持(在写作时)错误。

子查询使用MySQL的大多数版本的支持,所以你可以重写它,就像这样:

CREATE PROCEDURE AccountLedgerViewUnderBank() 

begin 

SELECT  ledgerId AS 'Account Ledger Id', 
      acccountLedgerName AS 'Account Ledger Name' 
FROM  tbl_AccountLedger 

where  accountGroupId 
    IN  (select accountGroupId 
      from tbl_AccountGroup where accountGroupId='9' 
      UNION ALL 
      select e.accountGroupId 
      from tbl_AccountGroup as e,GroupInMainGroup G 
      where e.groupUnder=G.accountGroupId) 
end ; // 
+0

谢谢..但你错过了;在第16行结束之前。 +5给你 – gangotri