在Oracle 11g中复制Excel的CHIDIST函数

我正在尝试在Oracle中复制Excel工作簿的function。 工作表上的一个公式使用CHIDIST,即“返回卡方分布的单尾概率”。 我在任何地方都看不到类似的function! 我将不得不写我自己的CHIDISTfunction?

这是CHIDIST上Excel文档的链接: http : //office.microsoft.com/en-gb/excel-help/chidist-HP005209010.aspx

我已经制定了广场和自由度。

谢谢

如果您使用CHIDIST进行卡方检验,那么STATS_CROSSTAB函数可能是一个不同的方法来达到同样的目的。 它将计算两组配对观测的卡方值,重要性或自由度。

右尾的概率…好…

在oracle中,您可以将java代码embedded到存储过程和函数中。 最好的方法是使用适当的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;