Oracle format model to Java
Translate a TO_CHAR format model into a Java pattern, preview what Oracle prints, and see the differences to handle in code.
Format models, Oracle to Java
Oracle's TO_CHAR and TO_DATE take a format model, a string of elements such as YYYY, MON or 999,999.99. Java has its own languages for the same job: DateTimeFormatter patterns for dates and DecimalFormat patterns for numbers. They look alike and mean slightly different things, which is how a migrated report ends up showing minutes where months should be (the classic mm versus MM slip).
Type an Oracle model and this tool shows the closest Java pattern, a live rendering of what Oracle would print for a sample date or number, and a list of the differences you still need to handle in code. Switch to the number tab for models such as FM9,990.00.
The differences that cause bugs
- Case: Oracle's MON, MONTH, DAY and DY follow the case you type; Java does not.
- Padding: Oracle pads names and numbers with spaces unless you add FM. Java does not pad.
- Fractional seconds: FF3 is milliseconds (SSS in Java); plain FF depends on the column's precision.
- Rounding: Oracle rounds half away from zero. DecimalFormat rounds half to even until you set RoundingMode.HALF_UP.
- Two-digit years: RR chooses the century from the current year; Java's yy uses a fixed base.
The rendering follows Oracle's documented rules for English sessions. Locale settings (NLS_DATE_LANGUAGE, NLS_TERRITORY) change names and separators, so test unusual cases against your database. The conversion runs in your browser and nothing is uploaded.
Frequently asked questions
What is the Java equivalent of Oracle YYYY-MM-DD HH24:MI:SS?
The DateTimeFormatter pattern yyyy-MM-dd HH:mm:ss. HH24 is a 24-hour clock, which is HH in Java; Oracle HH or HH12 is a 12-hour clock, which is hh in Java and needs AM/PM (a).
Why does Oracle print JAN but Java prints Jan?
Oracle follows the case of the format element: MON gives JAN, Mon gives Jan, mon gives jan. Java's MMM always prints the locale's name (Jan). Convert the result with toUpperCase(Locale.ROOT) if you need capitals.
What does FM do in a format model?
FM (fill mode) removes the padding Oracle adds: leading zeros on numbers, blanks after month and day names, and blanks on numbers. In Java most patterns are already unpadded when you use a single letter (d, M, H).
Why does a number format return #####?
The value has more integer digits than the model allows, so Oracle fills the result with # characters. Add more 9s to the model.