About the same in Oracle
2 LEVEL Month,
3 TO_CHAR(LAST_DAY(TO_DATE(LEVEL || '/1/' ||
4 TO_CHAR(SYSDATE, 'YYYY'), 'MM/DD/YYYY')),'DD') Days
7 CONNECT BY
8 LEVEL <= 12;
12 rows selected.
After the update in the parent, i realized this too could be shortened:
TO_CHAR(ADD_MONTHS(TO_DATE('1', 'DDD'), LEVEL) - 1, 'DD')
LEVEL < 13;
But, if we can cheat
and specify the year, using the ANSI date literal is slightly shorter:
TO_CHAR(ADD_MONTHS(DATE '2014-1-1', LEVEL) - 1, 'DD')
LEVEL < 13;
In a race with the parent to find the shortest SQL. :) So far we went with a literal data (which locks it to 2014), but he outdid me by removing the '20' from the date. Touché!
Though, not to be outdone, we'll find something shorter (as of update 4) and even go back to working for every year:
SELECT TO_CHAR(LAST_DAY(TO_DATE(LEVEL,'MM')),'DD')FROM Dual CONNECT BY
Saved 3 characters. :)
If we can start from December, we'll save 8 more characters (for a total of 11):
SELECT TO_CHAR(TO_DATE(LEVEL,'MM')-1,'DD')FROM Dual CONNECT BY LEVEL<13;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||