Day of year in HQL?
Is there any way to extract the day of year (1-366) from a date in HQL? Is the only option to extend the dialects I need and explicitly register the functions? I see that the HSQL and DB2 dialects have dayofyear registered, but no luck with Or开发者_运维问答acle or SQL Server...
As far as I can tell, the only standard date part functions available are year(), month(), day(), etc, and unless I'm missing something these aren't sufficient to calculate DOY...
As far as I can tell, the only solution is to extend the existing dialects. This turned out to be fairly painless:
public class SQLServerDialect extends org.hibernate.dialect.SQLServerDialect {
public SQLServerDialect() {
registerFunction( "dayofyear", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(dayofyear, ?1)" ) );
}
}
精彩评论