开发者

Localized month names in Firebird

I need to get various parts of a TIMESTAMP field - specifically year, localized month name (in Russian), day of month and hours interval (like '11 - 12').

Currently i came up with this:

select
extract (year from prt.dtbegin) as f_year,
(
  case e开发者_JAVA技巧xtract (month from prt.dtbegin)
    when 1 then 'Январь'
    when 2 then 'Февраль'
    /* ... */
    when 12 then 'Декабрь'
  end
) as f_month,
cast (lpad (extract (day from prt.dtbegin), 2, 0) as char(2)) as f_day,
(
  cast (lpad (extract (hour from prt.dtbegin), 2, 0) as char(2)) 
  || ' - '
  || cast (lpad (extract (hour from prt.dtbegin) + 1, 2, 0) as char(2)) 
) as f_hour
from prt

It works fine (interval '23 - 24' is OK at the moment), but I don't like it, especially CASE sentence with each and every month.

So, i'd like to know, is there any common way of getting localized month names in Firebird? Also, can i format extracted parts of timestamp, instead of current cast-lpad-extract construct?

Thanks in advance.


What about a reference table with the localised strings in them with a key of the month number. I thought this was done in the Firebird system tables, but have not been able to find documentation or the location in the system tables, if indeed it is there.

EDIT: I have checked the system tables, and the documentation, and the literals are not available within Firebird itself. Sorry :-)


Instead of CASE you can use DECODE builtin function: http://www.firebirdsql.org/refdocs/langrefupd21-intfunc-decode.html


I don't think there's a built-in feature for that. You should consider writing your own UDF for that. Once done, it's very simple to use. The following resources should point you in the right direction:

  • http://www.firebirdsql.org/index.php?op=useful&id=deatz_udf
  • http://www.firebirdfaq.org/faq83/
  • http://www.ibphoenix.com/downloads/writing_internal_udfs.pdf

I sure hope next major release (3.0) will support writing internal functions.

Update

Firebird 3.0 will support internal SQL Functions: http://tracker.firebirdsql.org/browse/CORE-2047

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜