Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

About the same in Oracle

SQL> SELECT 2 LEVEL Month, 3 TO_CHAR(LAST_DAY(TO_DATE(LEVEL || '/1/' || 4 TO_CHAR(SYSDATE, 'YYYY'), 'MM/DD/YYYY')),'DD') Days 5 FROM 6 Dual 7 CONNECT BY 8 LEVEL <= 12; MONTH DA ---------- -- 1 31 2 28 3 31 4 30 5 31 6 30 7 31 8 31 9 30 10 31 11 30 12 31 12 rows selected.

After the update in the parent, i realized this too could be shortened:

SELECT TO_CHAR(ADD_MONTHS(TO_DATE('1', 'DDD'), LEVEL) - 1, 'DD') FROM Dual CONNECT BY LEVEL < 13;
But, if we can cheat and specify the year, using the ANSI date literal is slightly shorter:
SELECT TO_CHAR(ADD_MONTHS(DATE '2014-1-1', LEVEL) - 1, 'DD') FROM Dual CONNECT BY 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 + LEVEL<13;

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;

In reply to Re^2: How do you remember the number of days in each month? by chacham
in thread How do you remember the number of days in each month? by chacham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found