| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3055 人关注过本帖
标题:为什么使用source命令执行sql脚本文件报错,但相同的内容通过命令行执行却没 ...
只看楼主 加入收藏
wade2006
Rank: 2
等 级:论坛游民
帖 子:49
专家分:27
注 册:2007-1-16
结帖率:100%
收藏
 问题点数:0 回复次数:0 
为什么使用source命令执行sql脚本文件报错,但相同的内容通过命令行执行却没任何的问题?
我的sql文件脚本:
-- Name: ordertotal_oo
-- Parameters: onumber = order_number
--             taxable = 0 if not taxable, 1 if taxable
--             ototal = order total variable
create procedure ordertotal_oo(
  in onumber int,
  in taxable boolean,
  out ototal decimal(8,2)
)comment 'Obtain order total, optionally adding tax'
begin
  -- Declare variable for total
  declare total decimal(8,2);
  -- declare tax percentage
  declare taxrate int default 6;
  -- Get the order total
  select sum(item_price*quantity)
  from orderitems
  where order_num = onumber
  into total;
  -- Is this taxable?
  if taxable then
    -- Yes, so add taxrate to the total
    select total+(total/100*taxrate) into total;
  end if;
  -- And finally, save to out variable
  select total into ototal;
end;
通过source命令执行脚本文件提示如下的错误:
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 '' at line 8
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 'declare taxrate int default 6' at line 1
ERROR 1327 (42000): Undeclared variable: total
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 'if taxable then
    select total+(total/100*taxrate) into total' at line 1
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 'end if' at line 1
ERROR 1327 (42000): Undeclared variable: ototal
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 'end' at line 1
但是相同的内容直接在命令行上运行却没报错,这是为什么啊?
搜索更多相关主题的帖子: source 脚本 sql 命令 文件 
2009-09-06 11:49
快速回复:为什么使用source命令执行sql脚本文件报错,但相同的内容通过命令行执 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043709 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved