注册 登录
编程论坛 MySQL论坛

为什么使用source命令执行sql脚本文件报错,但相同的内容通过命令行执行却没任何的问题?

wade2006 发布于 2009-09-06 11:49, 3055 次点击
我的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
但是相同的内容直接在命令行上运行却没报错,这是为什么啊?
0 回复
1