2013-04-22 28 views

回答

0

下面是一個簡短的實驗,看看會發生什麼。

create function determin_rand (i integer) 
returns float DETERMINISTIC 
return rand(); 

create function not_determin_rand (i integer) 
returns float 
return rand(); 

select determin_rand(1) as d1 , determin_rand(1) as d2, 
    not_determin_rand(1) as nd1, not_determin_rand(1) as nd2 

0.00850549154 0.831901073456 0.133989050984 0.174242004752 

由於值不同,函數每次都會被調用。在第一個函數中,我聲明它是確定性的,但它沒有什麼區別。

我爲你製作了一個sqlfiddle,用它來測試不同版本的mysql。

http://sqlfiddle.com/#!2/a8536/2

0

功能將被單獨調用每個計算。您可以在單個查詢中儘可能多次使用它。

相關問題