2012-09-12 28 views
0

我正在嘗試創建一個程序,以便找出一些利率價格等。這是一個小節選。mysql範圍程序sub

不過,我得到一個錯誤,指出:檢查語法附近「雙呼叫due_form(在amtDue,在extPrice雙」

是否在正確的範圍中的變量不是可能是什麼問題,有什麼建議?有非常大

create procedure due_form(in amtDue double 
          , in extPrice double 
          , in discAmt double 
          , in discPrice double 
          , in p_taxRate double 
          , out p_msg varchar(255)) 
    begin 
     set p_msg := concat(
    'Amount Due   ' , amtDue , '\n' 
    , 'Ext Price  ', extPrice, '\n' 
    , 'Disc Amount  ', discAmt, '\n' 
    , 'After Discount ', discPrice, '\n' 
    , 'Sales Tax  ', p_taxRate); 

    end; 
    # 
    create procedure due(in p_price double 
         , in p_quantity integer 
         , in p_discRate double 
         , in p_taxRate double 
         , in p_shipping double 
         , out p_amtDue double 
         , out p_msg varchar(255)) 
    begin 
declare extPrice double; 
declare discAmt double; 
declare discPrice double; 
declare amtDue double; 
declare msg varchar(255); 

select p_price, p_quantity, p_discRate, p_taxRate, p_shipping; 

set extPrice := p_price * p_quantity; 
set discAmt := extPrice * p_discRate; 
set discPrice := extPrice - discAmt; 
set amtDue:= discPrice * p_taxRate + p_shipping; 

set p_amtDue := amtDue; 

set msg := call due_form(in amtDue double 
            , in extPrice double 
            , in discAmt double 
            , in discPrice double 
            , in p_taxRate double 
            , out p_msg varchar(255)) 

set p_msg := msg; 

select p_msg; 

端;

回答

0

不能將過程的結果分配給一個變量,但p_msg將包含一個返回值,因爲它具有在前面的out關鍵字
當您調用過程時,您不得使用in/out,也不要重複每個參數的類型。該過程已被定義。

select p_price, p_quantity, p_discRate, p_taxRate, p_shipping; 

set extPrice := p_price * p_quantity; 
set discAmt := extPrice * p_discRate; 
set discPrice := extPrice - discAmt; 
set amtDue:= discPrice * p_taxRate + p_shipping; 

set p_amtDue := amtDue; 

call due_form(amtDue, extPrice, discAmt, discPrice, p_taxRate, p_msg); 

select p_msg; 
+0

我的答案是否解決了您的問題? – Jocelyn