這是我改成MSSQL的Java代碼。看看你的技巧。
CREATE FUNCTION dbo.fn_phaseOfMoon (@Date datetime)
RETURNS INT
BEGIN
Declare @y int,
@m int,
@d int,
@c int,
@e int,
@b int,
@jd float
Select @y = DatePart(yy, @Date), @m = DatePart(mm, @Date), @d = DatePart(dd, @Date)
/*
calculates the moon phase (0-7), accurate to 1 segment.
0 = > new moon.
4 => full moon.
*/
if (@m < 3)
Select @y = @y - 1, @m = @m + 12
Select @m = @m + 1;
Select @c = 365.25 * @y, @e = 30.6 * @m
Select @jd = @[email protected][email protected] /* jd is total days elapsed */
Select @jd = @jd/29.53 /* divide by the moon cycle (29.53 days) */
Select @b = convert(int, @jd) /* int(jd) -> b, take integer part of jd */
Select @jd = @jd - @b /* subtract integer part to leave fractional part of original jd */
Select @b = (@jd * 8) + 0.5 /* scale fraction from 0-8 and round by adding 0.5 */
if @b = 8
Select @b = 0 /* 0 and 8 are the same so turn 8 into 0 */
return @b
END
我不知道很多關於這些東西,所以你要檢查答案的是正確的Java代碼
來源:http://www.voidware.com/moon_phase.htm
感謝您的解決方案,即使是不同的有用。 – epoch 2012-03-12 11:39:46
嗨,我仍然有pl-sql函數?你可以分享嗎?謝謝。 – Motta 2017-11-25 17:59:41