2012-09-23 151 views
0
Create procedure a06_generate_data(p_loop_count int, 
            p_min int, 
            p_max int, 
            p_status char(1)) 
begin 

declare v_max int; 
declare v_min int; 
declare v_loop_count int; 

set v_max := p_max; 
set v_min := p_min; 
set v_loop_count := p_loop_count 

-- clear the results table for each run 
truncate table p_testbed.a06_rndData; 
Repeat 
    insert into p_testbed.a06_rndData (col_value) 
     values (floor(v_min + rand()*(v_max – v_min))); 
    set v_loop_count := v_loop_count – 1; 
until v_loop_count <= 0 End Repeat; 

select col_value p_testbed.a06_rndData ; 


end; # 

此過程是從p_min到p_max開始插入隨機值,總數爲p_loop_count值。但問題是,還有周圍的截斷的錯誤:mysql截斷錯誤

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 'truncate table   p_testbed.a06_rndData; 
    Repeat 
     insert into p_testbed.a0' 

我在網上搜索來檢查語法截形,但我想我有這個正確寫入。

對此提出建議?謝謝。

回答

1

的問題不在於TRUNCATE TABLE,前行缺少一個分號:

set v_loop_count := p_loop_count