2013-06-11 45 views

回答

0

右尾概率...好...

在oracle中可以嵌入Java代碼到存儲過程和函數。最好的方法是 使用適當的java類並從oracle的函數中調用它。這並不難:

http://docs.oracle.com/cd/B19306_01/java.102/b14187/chfive.htm http://jwork.org/scavis/api/doc.php/umontreal/iro/lecuyer/probdist/ChiDist.html

這就是我能爲你做:

DECLARE 
    l_value_to_evaluate NUMBER (10, 3) := 18.307; /* X; Value at which you want to evaluate the distribution */ 
    l_degrees_freedom NUMBER := 10;    /* Degrees of freedom */ 
    l_number NUMBER; 

    FUNCTION is_number(str_in IN VARCHAR2) RETURN NUMBER 
    IS 
     n NUMBER; 
    BEGIN 
     n := TO_NUMBER(str_in); 

     RETURN 1; 
    EXCEPTION 
     WHEN VALUE_ERROR THEN 
      RETURN 0; 
    END; 
BEGIN 
    -- If either argument is nonnumeric, CHIDIST returns the #VALUE! error value. 
    l_number := is_number(l_value_to_evaluate); 
    l_number := is_number(l_degrees_freedom); 

    -- If x is negative, CHIDIST returns the #NUM! error value. 
    IF SIGN(l_value_to_evaluate) = -1 THEN 
     RAISE_APPLICATION_ERROR(-20998, '#NUM!'); 
    END IF; 

    -- If degrees_freedom is not an integer, it is truncated. 
    l_degrees_freedom := TRUNC(l_degrees_freedom); 

    -- If degrees_freedom < 1 or degrees_freedom > 10^10, CHIDIST returns the #NUM! error value. 
    IF l_degrees_freedom < 1 
    OR l_degrees_freedom > POWER(10, 10) THEN 
     RAISE_APPLICATION_ERROR(-20997, '#NUM!'); 
    END IF; 

    -- CHIDIST is calculated as CHIDIST = P(X>x), where X is a χ2 random variable. 
    /* Here the integral's implementation */ 
EXCEPTION 
    WHEN VALUE_ERROR THEN 
     RAISE_APPLICATION_ERROR(-20999, '#VALUE!'); 
END; 
+0

嗨,謝謝你的建議!我寧願有一個解決方案,不需要這樣做 - 看起來像創建自己的PLSQL函數一樣簡單。我真的很想知道是否實際上有一種方法可以使用現有的函數在純Oracle SQL中執行此操作。如果不是,那麼我可能不得不實施您的建議或將現有代碼翻譯成PL/SQL。 – user1578653

+0

我會幫你,但我從來沒有實施積分。 –

+0

好吧,我試過了......你可以在我的不完整回覆中找到它... –

0

如果您使用CHIDIST做了卡方檢驗,該STATS_CROSSTAB功能對於相同的目的可能是不同的方式。它將計算兩組配對觀測的卡方值,重要性或自由度。