Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 创建临时表存储过程时出现我的sql错误_Mysql_Sql - Fatal编程技术网

Mysql 创建临时表存储过程时出现我的sql错误

Mysql 创建临时表存储过程时出现我的sql错误,mysql,sql,Mysql,Sql,我有一个存储过程查询并在临时表中插入值。。但显示出错误 delimiter // create procedure AccountLedgerViewUnderSundryDebtorCreditorCash() begin create temporary table temp_kk(accountGroupID varchar(50),HierarchyLevel varchar(50)); insert into temp_kk(accountGroupID,Hierar

我有一个存储过程查询并在临时表中插入值。。但显示出错误

delimiter //
create procedure AccountLedgerViewUnderSundryDebtorCreditorCash()
begin
    create temporary table temp_kk(accountGroupID varchar(50),HierarchyLevel varchar(50));

    insert into temp_kk(accountGroupID,HierarchyLevel)
        select accountGroupId,  1 as HierarchyLevel from tbl_AccountGroup 
        where accountGroupId='27'or accountGroupId = '28'or 
        accountGroupId = '11';

    create temporary table temp_kk2(accountGroupID varchar(50),HierarchyLevel varchar(50));     

    insert into temp_kk2(accountGroupID,HierarchyLevel)
        select e.accountGroupId, G.HierarchyLevel + 1 AS HierarchyLevel 
        from tbl_AccountGroup as e, temp_kk G 
        where e.groupUnder=G.accountGroupId  ;

    create temporary table temp_kk3(accountGroupID varchar(50),HierarchyLevel varchar(50));     

    insert into temp_kk3(accountGroupID,HierarchyLevel)
        select * from temp_kk union all temp_kk2 ;

    SELECT  
ledgerId AS 'Account Ledger Id',  
accountLedgerName AS 'Account Ledger Name',  
accountGroupId AS 'Account Group Id',  
openingBalance AS 'Opening Balance',  
debitOrCredit AS 'Credit Or Debit',  
defaultOrNot AS 'Editable Or Not',  
description AS 'Description'  


FROM tbl_AccountLedger  
where accountGroupId IN (select accountGroupId from temp_kk3);

end //
delimiter ;
1064-您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解可在“temp_kk2”附近使用的正确语法;在第20行选择分类帐作为[科目分类帐Id],acccountLedgerName'

这一行:

    select * from temp_kk union all temp_kk2 ;
需要:

    select * from temp_kk union all select * from temp_kk2 ;
至少,这是最明显的

不过,我倾向于避免使用
select*
。如果您更改临时表,它将断开。如果您不确定要从中选择的表中的所有列是什么,那么这也会使代码更难阅读。是的,它现在可以为您节省一些键入时间,但是当您以后必须继续查看表定义以确定您选择的确切内容时,您将失去节省的时间

不过,有了这些简单的临时表,就没什么大不了的了。

这一行:

    select * from temp_kk union all temp_kk2 ;
需要:

    select * from temp_kk union all select * from temp_kk2 ;
至少,这是最明显的

不过,我倾向于避免使用
select*
。如果您更改临时表,它将断开。如果您不确定要从中选择的表中的所有列是什么,那么这也会使代码更难阅读。是的,它现在可以为您节省一些键入时间,但是当您以后必须继续查看表定义以确定您选择的确切内容时,您将失去节省的时间

不过,有了这些简单的临时表,就没什么大不了的了